On Thu, Jan 13, 2005 at 07:35:19PM -0500, Joe Gottman wrote:
> In Perl5, given code like
>
> for (my $n = 0; $n < 10; ++$n) {.}
>
> the control variable $n will be local to the for loop. In the equivalent
> Perl6 code
> loop my $n = 0; $n < 10; ++$n {.}
>
> $n will not be local to the loop but will instead persist until the end of
> enclosing block.
Actually, I consider this a good thing. There are lots of times when
I would LIKE my loop variable to persist and, in order to get that, I
need to do the following:
my $n;
for ($n=0; $n<10; ++$n) {...}
...do stuff with $n...
It's a minor ugliness, but it itches at me. Under the new Perl6
rules, I can easily have it either way.
{for (my $n=0; $n<10; ++$n) {...}} # Local to loop
for (my $n=0; $n<10; ++$n) {...} # Persistent
--Dks