in reply to Re^3: Scope and references
in thread Scope and references
Hint: I failed.use strict; use Data::Dumper; my @array; for (my $i = 0; $i < 5; ++$i) { LABEL: my @y; push(@y, $i); push(@array, \@y); if ($i & 1) { ++$i; goto LABEL; } } print(Dumper(\@array), "\n");
Evidently, executing a my does not replace its arguments. They hang around until they go out of scope.$VAR1 = [ [ 0 ], [ 1, 2 ], $VAR1->[1], [ 3, 4 ], $VAR1->[3] ];
Extra credit. What if
is replaced withmy @y;
I was right about one thing. Lexical variable scoping is not intuitively obvious. Fortunately, "ordinary" use is seldom so obscure.my @y = ();
|
|---|