> But by using the term ‘variable’, which is ambiguous, you are not
> answering my question! :-)
Sorry. I tend to think of *every* variable name as merely being
an alias for some underlying storage mechanism. ;-)
> Does
>
> my $x;
> for 1..10 -> $x {}
>
> cause the existing name $x to refer temporarily to each of the numbers,
> or is a new $x name created?
A new one is created (each time through the loop).
> What does this do?
>
> my $x;
> my sub f { say $x }
> for 1..10 -> $x { f(); }
It prints 'Any()' ten times (i.e. the equivalent of printing ten Perl 5 undefs).
The two $x's definitely exist at the same time during the loop.
For example, this:
my $x = 'outer x';
my sub f { say $x }
for 1..10 -> $x {
print $x, ": ";
f();
}
prints:
1: outer x
2: outer x
3: outer x
4: outer x
5: outer x
6: outer x
7: outer x
8: outer x
9: outer x
10: outer x
Damian