in reply to Re: for loops
in thread for loops, closures
Excellent! Okay, but, why does it work? Does that mean that for (my $i;;) gives my a ref to a lexical variable instead of the actual variable? Hm, or a ref to a copy of whatever is in the init part? That doesn't seem to be it, because moving my $i before the for (;;) doesn't fix it, either.
Can anybody explain the scoping differences between these lines:
In all three, $i disapears after the closing brace. So, why does the middle one fail with closures?for my $i (1) { print $i } for ( my $i = 1; $i; $i--) { print $i } for ( my $i = 1; $i; $i--) { my $i = $i; print $i }
Paris Sinclair | 4a75737420416e6f74686572 pariss@efn.org | 205065726c204861636b6572 http://sinclairinternetwork.com
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE (tilly) 3 (closures): for loops
by tilly (Archbishop) on Aug 21, 2000 at 00:41 UTC | |
by BlaisePascal (Monk) on Aug 21, 2000 at 00:55 UTC | |
by tilly (Archbishop) on Aug 21, 2000 at 01:11 UTC | |
by Aighearach (Initiate) on Aug 21, 2000 at 05:14 UTC |