Jean
Jean

Reputation: 22745

Increase verbosity of Perl warnings

Is there a way to increase the verbosity of warnings in Perl ? I use this to generate warnings.

#!/usr/bin/perl -w

I am especially interested in the following which I hit occasionally. Is there anyway Perl can print the name of uninitialized variable ?

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

Upvotes: 3

Views: 3427

Answers (3)

TLP
TLP

Reputation: 67920

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);

Upvotes: 2

cirne100
cirne100

Reputation: 1558

#!/usr/bin/perl
use diagnostics;
#or
#use diagnostics -verbose;

this will give you more information!
http://perldoc.perl.org/diagnostics.html

Upvotes: 2

friedo
friedo

Reputation: 67058

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

Upvotes: 9

Related Questions