( 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}
In reply to Re: Why nothing from 'strict' or 'warnings' with deref'd undef value?
by ikegami
in thread Why nothing from 'strict' or 'warnings' with deref'd undef value?
by jeremym
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |