Verbose warnings

T

Tad McClellan

Louis Erickson said:
: Greg Bacon wrote:
:> In article <[email protected]>,
:>
:> : Is there any way to find out WHICH variable is uninitialized,

Couldn't they just put:

no warnings qw(uninitialized);
Or am I missing something really simple here?


I think so.

It does not answer the question that was asked above. :)


I think we are working under the assumption that the uninitialized
value is a bug, and we're trying to find it so it can be fixed
(rather than masked).
 
R

Randal L. Schwartz

Louis> Couldn't they just put:

Louis> no warnings qw(uninitialized);

Louis> ... around the flaky section of code?

Not and be compatible with Perl 5.5, which is still alive and
well in many sites.
 
A

Anno Siegel

Richard Voss said:
Greg said:
: Is there any way to find out WHICH variable is uninitialized, short of
: breaking a line up into bunches of single lines?
: [...]

Here's a start:

that will only work with package variables, not with lexicals.

I recommend the debugger.

I have occasionally used something along these lines, which works for
lexicals and package variables, and, in fact, for arbitrary Perl
expressions:

sub report_undef {
my $vars = join ', ', map "'$_'", @_;
my $expr = qq|join( ', ', grep not( defined( eval( \$_))), $vars)|;
qq|print 'undef: ', $expr, "\\n"|;
}

If the code is, for example,

my ( $a, $b, $s, $k, $f);
$b = 123;
$k = 'aaa';

add the line

eval report_undef( qw( $a $b $s $k $f));

to see that $a, $s, and $f are undefined. You still have to type
"eval" literally, and name the variables you want to check. This
is necessary (along with the weirdness of the code in report_undef()),
so that the variables you want to check don't have to be in the
scope where report_undef() is compiled.

Anno
 
G

Greg Bacon

: Greg Bacon wrote:
:
: > Here's a start:
: > [...]
:
: that will only work with package variables, not with lexicals.
:
: I recommend the debugger.

So? The OP said he's dealing with package variables.

Greg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top