Perl 是否正确处理 Solaris 上源代码中的 Windows 样式的行结尾?

Does Perl correctly handle Windows-style line endings in source code on Solaris?

Perl 是否正确处理 Solaris 上源代码中的 Windows 式行结尾?换句话说,如果一个 Perl 脚本在一行的末尾有一个 ^M,当它在 Solaris 机器上是 运行 时,perl 会正确解析它吗?

if(/fmr_dest/) { 
    do_traffic($dbc, 'rprice', '-MSG_RESP', $customer_no, $data{$customer_no}{$action_type});
    next;
}

if(/fmr_rate/) { ## Change to customer rates^M
    do_traffic($dbc, 'rprice', '-MSG_RESP', $customer_no, $data{$customer_no}{$action_type});^M
    next;^M
}^M

if(/conn/) {
    ...

您脚本中的神器运输 returns (\r) 至少会以两种方式毁掉您的一天:

  1. 正如 ThisSuitIsBlackNot 在评论中指出的那样,多行字符串包含的内容和它们看起来包含的内容之间会有混淆——这会影响行的长度,[=11 的行为=]和chop、多行正则表达式匹配、字符串比较等

  2. 更严重的是,a carriage return at the end of your shebang (#!/usr/bin/perl\r) 会导致 shell 无法直接执行您的脚本,因为它会寻找一个名为"/usr/bin/perl" . chr(10)解读一下。

神器回车returns在你的程序中输入can also come back bite you.