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

时间:2016-02-25 20:52:07

标签: perl 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/) {
    ...

1 个答案:

答案 0 :(得分:4)

脚本中的神器回车(\r)将至少以两种方式毁掉你的一天:

  1. 由于ThisSuitIsBlack没有在评论中指出,您的多行字符串包含的内容与它们包含的内容之间会存在混淆 - 这会影响行长度,chomp和{的行为{1}},多行正则表达式匹配,字符串比较等

  2. 更严重的是,a carriage return at the end of your shebangchop)会导致shell无法直接执行您的脚本,因为它会查找名为#!/usr/bin/perl\r的程序来解释它

  3. 神器回车在您的计划输入中can also come back to bite you返回。