I think the problem is that your named sub is only compiled once when the surrounding sub is compiled (or there abouts).

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


In reply to Re: Perl scoping not logical...? by jettero
in thread Perl scoping not logical...? by perl-diddler

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.