in reply to Perl scoping not logical...?
What you want is a sub that's compiled each time throught he loop (so it uses the lexicals from this run instead of the first run.
sub test { my $global_lexical_sorta = 0; my $other = 0; my $local_sub = sub { $global_lexical_sorta ++ }; sub named { $other ++ } $local_sub->() for 1 .. 10; &named for 1 .. 10; print "$global_lexical_sorta $other\n"; } &test; &test; # you get 10 10 -- $gls and $o are each incremented to 10 # and 10 0 -- the second $gls is incremented to 10, but ... # the first $o is incremented to 20 while the second $o is not increme +nted!
You also seem to be crushing some of your locals... You have my ($rq_nam, $rq_vr, $rq_op);, but also re-my them where you set them equal to @_. That could easily be the actual problem. Not sure.
-Paul
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Perl scoping not logical...?
by perl-diddler (Chaplain) on Apr 27, 2008 at 23:35 UTC | |
by jettero (Monsignor) on Apr 28, 2008 at 11:16 UTC | |
by perl-diddler (Chaplain) on May 01, 2008 at 01:50 UTC | |
by ysth (Canon) on May 02, 2008 at 04:07 UTC |