Consider this:
use Data::Dumper; use List::Util qw(first); my @x = ({"aaa" => 100}); [grep { $_->{"aaa"} < 4 } @x]->[0] = 'foo'; (first { $_->{"aaa"} < 4 } @x) = 'foo';
Line 6 (grep) executes fine. Line 7 (first) dies with:
Can't modify non-lvalue subroutine call of &List::Util::first in list assignment at foo.pl line 7, near "'foo';"
You're putting the results of your grep into an arrayref. That arrayref and its elements are lvalues—they can be assigned to—so autovivification can happen to them.
In reply to Re: Why are these undefs different?
by tobyink
in thread Why are these undefs different?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |