David Storrs wrote:
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
But there's no clean way to make some of them temporary and some
persistent.
This seems like a legitimate place for "saying what you intend", viz:
for (my $n is longlasting = 0, $m = 1; ...) {...}
Albeit that's a lame example of how to do it.
=Austin
--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.6.10 - Release Date: 1/10/2005