Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^2: Unexpected warning

by LanX (Saint)
on Nov 18, 2013 at 15:00 UTC ( [id://1063110]=note: print w/replies, xml ) Need Help??


in reply to Re: Unexpected warning
in thread Unexpected warning

> You get that warning on that line if $something is undefined.

yep I can reproduce this. =)

Seems like in the context of the call warnings were disabled.

DB<132> use warnings; sub tst {my $a=shift, my $b =shift} DB<133> %h=() DB<134> $bla="" => "" DB<135> tst $h{$bla} => (undef, undef) DB<136> undef $bla => undef DB<137> tst $h{$bla} Use of uninitialized value in scalar assignment at (eval 81)[multi_per +l5db.pl:644] line 2.

Cheers Rolf

( addicted to the Perl Programming Language)

Replies are listed 'Best First'.
Re^3: Unexpected warning
by salva (Canon) on Nov 18, 2013 at 15:08 UTC
    I can reproduce it myself too now:
    tst(undef); # doesn't warn from tst tst($foo{undef}); # doesn't warn from tst tst($foo{$undef}); # warns from tst
    I would say this is a bug in perl, or I am missing something?

      The undef value is subtly different from using an undefined variable, so that may be causing the problem.

      tst($foo{undef});  # doesn't warn from tst

      This uses the undef value as a key into the %foo hash; the key presumably doesn't exist so Perl returns undef. This is working as I would expect.

      tst($foo{$undef});  # warns from tst

      This looks up the value of $undef, which presumably isn't defined, so Perl should flag an error at that statement, not inside tst. If that is the case, then it, too, is working as I would expect.

Re^3: Unexpected warning
by hdb (Monsignor) on Nov 18, 2013 at 15:07 UTC

    I get no warnings from the code below:

    use strict; use warnings; sub test { my $x = shift; } my %hash = ( a => "a" ); test $hash{"b"};
      The key must be undef.

      lanx@nc10-ubuntu:~$ perl use strict; { use warnings; sub test { my $x = shift; } } my %hash = ( a => "a" ); my $key; test $hash{$key} Use of uninitialized value in scalar assignment at - line 3. lanx@nc10-ubuntu:~$ perl -version This is perl, v5.10.0 built for i486-linux-gnu-thread-multi

      I agree with salva that this is kind of a bug in lexical warnings.

      Cheers Rolf

      ( addicted to the Perl Programming Language)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1063110]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-04-23 19:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found