in reply to Why nothing from 'strict' or 'warnings' with deref'd undef value?
( Please use <c> instead of <pre>. Less work for you, more features for us. )
Append the following, and you'll see why it's not an error:
print "$array_ref->[0]\n";
You asked for a hash reference, so Perl obliged rather that giving an error. It's a very convenient (although sometimes problematic) feature called "autovivification". Solution:
use strict; use warnings; my $array_ref = [undef]; if ( $array_ref->[0] # <--- && $array_ref->[0]->{whatever} ) { print "true\n"; } else { print "false\n"; }
Note that the arrow is optional between indexes, so
$array_ref->[0]->{whatever}
can be written as
$array_ref->[0]{whatever}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Why nothing from 'strict' or 'warnings' with deref'd undef value?
by jeremym (Initiate) on Apr 02, 2009 at 23:45 UTC | |
by ikegami (Patriarch) on Apr 03, 2009 at 02:03 UTC | |
by jeremym (Initiate) on Apr 03, 2009 at 16:50 UTC |