Search code examples
perlautovivification

Why autovivification works at 'for'?


I have next code:

print   for @{ $events->{ $name } };

When $events is empty hash I got $name key which value is empty array []

Why autovivification works despite on that I just access element and assign nothing to it?


Solution

  • Assigning doesn't autovivify; evaluating as an lvalue so that you can assign does.

    Foreach's list expression is evaluated as an lvalue to allow $_ = 1 for @a;