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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|