Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^2: Unexpected warning

by samwyse (Scribe)
on Nov 18, 2013 at 17:11 UTC ( #1063168=note: print w/replies, xml ) Need Help??


in reply to Re: Unexpected warning
in thread Unexpected warning

This should be pretty definitive...
use strict; use warnings; sub tst { warn "entering tst()\n"; my $arg = shift; # line 6 warn "leaving tst()\n\n"; } my %h=(); tst $h{''}; tst $h{undef}; # line 12 my $bla=''; tst $h{$bla}; # line 14 $bla=undef; tst $h{$bla}; # line 16 undef $bla; tst $h{$bla}; # line 19
And here's the results:
entering tst() leaving tst() entering tst() leaving tst() entering tst() leaving tst() Use of uninitialized value $bla in hash element at perlmonks-1063097.p +l line 16. entering tst() Use of uninitialized value in scalar assignment at perlmonks-1063097.p +l line 6. leaving tst() Use of uninitialized value $bla in hash element at perlmonks-1063097.p +l line 18. entering tst() Use of uninitialized value in scalar assignment at perlmonks-1063097.p +l line 6. leaving tst()

Turning off 'strict' has no effect, while turning off 'warnings' warnings gets rid of the messages.

I'm actually surprised by a couple of aspects of this. First, I expected $bla=undef; tst $h{$bla} to behave the same as tst $h{undef}; it didn't. Instead, $bla=undef seems to have the same effect as undef $bla. Second, it seems that lines 16 and 19 are generating a value other than a simple undef to pass into the subroutine, otherwise the invocation in line 12 would have also generated an error in line 6.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2020-11-28 06:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?