有没有办法增加 Perl 中警告的详细程度?我用它来生成警告。
#!/usr/bin/perl -w
我对偶尔遇到的以下内容特别感兴趣。无论如何 Perl 可以打印未初始化变量的名称吗?
Use of uninitialized value in printf at ./script.pl line 106, <LOG> line 323805.
It will try to if you upgrade to Perl 5.10 or later. 5.14 is current.
As friedo says, it sounds like you have an older perl version. However, debugging with print
is fairly straightforward, and a good "low tech" technique to be aware of. If you have a line such as:
printf "%-10s %-10s %s %s", $var1, $var2, @array;
And you get a warning that is hard to place to either variable, you can always split it up:
printf "%-10s ", $var1;
printf "%-10s ", $var2;
printf "%s %s", @array;
Then you will get a more specific warning.
Or you can get a little creative, and do:
sub no_undef {
my @return;
push @return, map { defined $_ || "undef" } @_;
return @return;
}
printf "%-10s %-10s %s %s", no_undef($var1, $var2, @array);
#!/usr/bin/perl
use diagnostics;
#or
#use diagnostics -verbose;
这将为您提供更多信息!
http://perldoc.perl.org/diagnostics.html