3

有没有办法增加 Perl 中警告的详细程度?我用它来生成警告。

#!/usr/bin/perl -w

我对偶尔遇到的以下内容特别感兴趣。无论如何 Perl 可以打印未初始化变量的名称吗?

Use of uninitialized value in printf at ./script.pl line 106, <LOG> line 323805.
4

3 回答 3

9

It will try to if you upgrade to Perl 5.10 or later. 5.14 is current.

于 2011-06-22T21:48:47.700 回答
2

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);
于 2011-06-22T22:32:53.970 回答
2
#!/usr/bin/perl
use diagnostics;
#or
#use diagnostics -verbose;

这将为您提供更多信息!
http://perldoc.perl.org/diagnostics.html

于 2011-06-22T21:55:58.900 回答