I'm seeing an odd behavior wehere the "Can't use an undefined value as an ARRAY reference at ..." is generated when expected but not when map() and grep() are involved.
Here's the code. In the first case with map(), perl runs without an error (ditto for grep). But in the second case, without any map or grep, the expected error is thrown becaus the value being dereferenced is undefined.
use strict; use warnings; my $this_key = "NOT_IN_HASH"; my $hash_ref = {}; my @items; if (0) { # this gives no error @items = map { $_->{value} } @{$hash_ref->{$this_key}}; } else { # but this generates to the expected error. @items = @{$hash_ref->{$this_key}}; }
Am I missing something obvious? Is this behavior intentional?
Thank you.
In reply to map() and grep() suppress "Can't use an undefined value as an ARRAY reference at ..." errors by icanhezperl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |