Here another kind of aliasing with the same "weirdness"
$ perl -wE 'my %h; sub tst{ say @_ }; tst ( @{$h{a}} ); exists $h{a} a +nd print "true\n"' true
I seem to remember we already had a similar discussion here not long ago...
Now I remember, because of the aliasing, it's also an lvalue, i.e. it's potentially possible to assign to $x and consequently create the key.
But the autovivification happens at the moment of aliasing, and not at the moment of assignment, because it's too complicated to implement.
And yes, we had this discussion some month ago, I'll try to find the thread.
Bottomline was that it's very complicated to cover all edge cases, and the devs want to keep the code simple.
Compare unexpected modify hash in a distance with grep { $_ }
Cheers Rolf
(addicted to the Perl Programming Language :)
see Wikisyntax for the Monastery
In reply to Re: autovivified hash key with foreach $x ( @{$h{a}} ) {}. (Update x2)
by LanX
in thread autovivified hash key with foreach $x ( @{$h{a}} ) {}
by Danny
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |