Front page | perl.perl5.porters |
Postings from September 2013
Re: variable warnings
Thread Previous
From:
Dave Mitchell
Date:
September 30, 2013 20:59
Subject:
Re: variable warnings
Message ID:
20130930205933.GE2278@iabyn.com
On Sat, Sep 28, 2013 at 01:35:21PM -0000, Father Chrysostomos wrote:
> 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.
In case this isn't clear to people, the code currently distingushes between
PL_sv_undef and a general undef SV; if the former is the undef value, then
its harder to work out which thing triggered the undef warning.
So you get:
$ p -wE 'my @x; say $x[1]'
Use of uninitialized value in say at -e line 1.
$ p -wE 'my @x = (1, undef); say $x[1]'
Use of uninitialized value $x[1] in say at -e line 1.
> 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!).
Sounds like an idea. I'm not volunteering :-)
--
Never do today what you can put off till tomorrow.
Thread Previous