打印所以这里是正在运行的代码片段:非常奇怪的错误。当在Perl
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
是我们的迭代变量。以下是此代码的特定runthrough的输出结果。为了保护隐私,我用###。###。###。###替换了IP中的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#.###
正如你所看到的,这有几个问题。
- 以“地址”开头的行以空格开头,而不是打算的$。
- 之后的行以“到地址条目”开始,而不是“$到打印的最终值”。
- 该行在结尾处也没有“地址条目”。
- 最后两行之间有一个额外的换行符。
- 最后一行不包含单词“添加zix01 A”,即使它应该打印的变量确实如此。
- 最后一行也不包括它应该打印的IP,除了最后5个字符以外,这些字符在字符串的其余部分之后但在换行符之前出现。
有没有人有任何想法这里发生了什么?
编辑为语法。
这不一定与您的问题有关,但我已经看到由打印输出缓冲区引起的各种奇怪的打印行为。把它放在脚本的顶部,试着关掉它:$ | = 1; – Magnus