用Perl说\n\r \n换行

now*_*wox 1 perl dos

我想使用saydos换行格式:

say "foo" 应该显示 foo\r\n

我试图重新定义新的行变量,但它不会改变任何东西

 local $/="\r\n"; 
Run Code Online (Sandbox Code Playgroud)

另一个解决方案是手动编写:

 print "foo\r\n"; 
Run Code Online (Sandbox Code Playgroud)

但它不是很方便

ike*_*ami 7

不要使用影响所有句柄的全局变量; 使用

open(my $fh, '>:crlf', ...)
Run Code Online (Sandbox Code Playgroud)

要么

binmode($fh, ':crlf')
Run Code Online (Sandbox Code Playgroud)

:crlf默认情况下已在Windows计算机上为您添加,但是在其中指定open或尝试将其添加到已使用它的句柄中binmode也不会有任何损害.