所以这是正在运行的代码片段:
if($verbose){
my $toPrint = "Added ";
if($types[$count]){
$toPrint .= "$types[$count] ";
print "Type: $types[$count]\n"; #Manual debugging
print "\$toPrint: $toPrint\n"; #Manual debugging
}
if($addressTypes[$count]){
$toPrint .= "$addressTypes[$count] ";
print "Address Type: $addressTypes[$count]\n"; #Manual debugging
print "\$toPrint: $toPrint\n"; #Manual debugging
}
if($addresses[$count]){
$toPrint .= "$addresses[$count] ";
print "Address: $addresses[$count]\n"; #Manual Debugging
print "\$toPrint: $toPrint\n"; #Manual debugging
}
$toPrint .= "to the address entries\n";
print "Final value of \$toPrint before printing: $toPrint\n"; #Manual debugging
print $toPrint;
}
我们在for循环中,$count
是我们正在迭代的变量。以下是此代码的特定结果的输出结果。为了保护隐私,我用###。###。###。###替换了IP。
Type: zix01
$toPrint: Added zix01
Address Type: A
$toPrint: Added zix01 A
Address: ###.###.###.###
toPrint: Added zix01 A ###.###.###.###
to the address entries before printing: Added zix01 A ###.###.###.###
to the address entries#.###
正如您所看到的,这有几个问题。
有谁知道这里发生了什么?
为语法编辑。
答案 0 :(得分:5)
输出中的某处是否有回车字符(\r
)?在Unix上使用perl script.pl | od -c
来检查输出的每个字符。
Windows中生成的文件通常有\r\n
行结尾。在Unix环境中读取这些文件时,chomp
将仅删除\n
。当我不得不担心可移植性时,我通常会跳过chomp
并在输入上说s/\s+$//
(如果您不想删除所有,请s/[\r\n]+$//
尾随空格。)