develooper Front page | perl.perl5.porters | Postings from September 2013

Re: variable warnings

Thread Previous | Thread Next
From:
Father Chrysostomos
Date:
September 28, 2013 13:35
Subject:
Re: variable warnings
Message ID:
20130928133521.25787.qmail@lists-nntp.develooper.com
Yves Orton wrote:
> We do. The problem is it isn't always triggered:
> 
> $ ./perl -Ilib -e'use warnings; $x = 5 + $x{foo};'
> Use of uninitialized value $x{"foo"} in addition (+) at -e line 1.
> $ ./perl -Ilib -e'use warnings; $x = $x + $x{foo};'
> Use of uninitialized value in addition (+) at -e line 1.
> Use of uninitialized value $x in addition (+) at -e line 1.
> 
> I don't know why not, or what the circumstances are for it to trigger exactly.

When you have 5+$x{foo}, only one argument could possible be the
source of the warning, so it is reported.

When there are multiple variable args, the only way to know which
caused the warning is to check memory addresses.

uninit_var currently punts on trying to figure out which element of an
aggregate is responsible.  I think it would just be a matter of having
it iterate arrays and hashes (but without resetting hash iterators or
calling tie methods!).


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About