in reply to Re^2: Automatic Loop Counter not in perl
in thread Automatic Loop Counter not in perl
Why not just make it a stack?
What do you think local is doing?
One of the cool things about localizable variables is that when you take a reference to one, you're getting a reference to that instance of it in its internal stack. So, if you need to reach back to values in outer scopes, you can take references to the variable at those levels.
use strict; use warnings; our $LC = 'o'; my $lc0 = \$LC; for ( local $LC = 0; $LC < 3; $LC++ ) { my $lc1 = \$LC; for ( local $LC = 0; $LC < 3; $LC++ ) { print "lc0=$$lc0, lc1=$$lc1, LC=$LC, \n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Automatic Loop Counter not in perl
by holli (Abbot) on Aug 21, 2007 at 20:12 UTC |