perl - 打印 $/而不是\n 是错误的吗?

标签 perl newline

Perl 的文档说 $/是:

The input record separator, newline by default. This influences Perl's idea of what a "line" is.



那么,基本上是错误的:

print STDERR $var, $/;

代替:

print STDERR "$var\n";

?

如果我做前者会出什么问题?

最佳答案

也许您正在寻找输出记录分隔符?

perldoc perlvar:

 IO::Handle->output_record_separator( EXPR )
   $OUTPUT_RECORD_SEPARATOR
   $ORS
   $\

The output record separator for the print operator. If defined, this value is printed after the last of print's arguments. Default is "undef".

You cannot call "output_record_separator()" on a handle, only as a static method. See IO::Handle.

Mnemonic: you set "$\" instead of adding "\n" at the end of the print. Also, it's just like $/, but it's what you get "back" from Perl.



例如,
$\ = $/;
print STDERR $var;

关于perl - 打印 $/而不是\n 是错误的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31388841/

相关文章:

linux - 如何在 Perl 中对需要 JavaScript 的页面进行网络测试?

mysql - 使用 INSERT INTO ... ON DUPLICATE KEY 时绑定(bind) MySQL 变量

perl - 当函数 my_func() 导出但未定义时,为什么 *main::my_func{CODE}* 是一个 coderef?

c++ - 使用 '\n' 而不是 endl 会影响输出,为什么?

regex - 如何在保持大写的同时替换文本?

perl - 调用 perl 脚本

newline - Document.xml 属性的 MSXML 和换行规范化(?)

c++ - 以列表格式读取文件时如何忽略换行符

python - 在 python 3 str.format 中抑制打印换行符

JPA/EclipseLink - 使用一条 SQL 语句创建多行脚本源