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

Re: variable warnings

Thread Previous | Thread Next
From:
demerphq
Date:
September 24, 2013 08:01
Subject:
Re: variable warnings
Message ID:
CANgJU+Xagd0Lce2MNBJGWJCN+_xPKr8_GMa=yn75xe+F1pc0AA@mail.gmail.com
On 24 September 2013 08:19, H.Merijn Brand <h.m.brand@xs4all.nl> wrote:
> I've got used to the ultimately helpful warnings for *which* variable
> is undefined:
>
> $ perl -wE'say $x'
> Name "main::x" used only once: possible typo at -e line 1.
> Use of uninitialized value $x in say at -e line 1.
> $ perl -wE'my $x; say $x'
> Use of uninitialized value $x in say at -e line 1.
>
> Would it be possible to extend that to containers in arrays and hashes?
>
> $ perl -wE'my @x; say $x[1]'
> Use of uninitialized value in say at -e line 1.
> $ perl -wE'my %x; say $x{foo}'
> Use of uninitialized value in say at -e line 1.
>
> =>
>
> $ perl -wE'my @x; say $x[1]'
> Use of uninitialized value $x[1] in say at -e line 1.
> $ perl -wE'my %x; say $x{foo}'
> Use of uninitialized value $x{foo} in say at -e line 1.

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.

You can see tests in: t/lib/warnings/9uninit


cheers,
Yves

-- 
perl -Mre=debug -e "/just|another|perl|hacker/"

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