in reply to Re^3: Scope and references
in thread Scope and references

Here's a test of understanding. What does the following produce?
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");
Hint: I failed.
$VAR1 = [ [ 0 ], [ 1, 2 ], $VAR1->[1], [ 3, 4 ], $VAR1->[3] ];
Evidently, executing a my does not replace its arguments. They hang around until they go out of scope.

Extra credit. What if

my @y;
is replaced with
my @y = ();
I was right about one thing. Lexical variable scoping is not intuitively obvious. Fortunately, "ordinary" use is seldom so obscure.