It is because the for
loop treats contents of @$a
as lvalues--something that you can assign to. Remember that for
aliases the contents of the array to $_
. It appears that the act of looking for aliasable contents in @$a
, is sufficient to cause autovivification, even when there are no contents to alias.
This effect of aliasing is consistent, too. The following also lead to autovivification:
map {stuff} @$a;
grep {stuff} @$a;
a_subroutine( @$a);
If you want to manage autovivification, you can use the eponymous pragma to effect lexical controls.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…