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"; } }
A word spoken in Mind will reach its own level, in the objective world, by its own weight

Replies are listed 'Best First'.
Re^4: Automatic Loop Counter not in perl
by holli (Abbot) on Aug 21, 2007 at 20:12 UTC
    I am aware what local does, i've used it in various occasions. Having a "real" stack (array), would save me from having to do the extra typing of creating an explicit reference. And I could even know the loop count of whatever outer code calls MY code.


    holli, /regexed monk/