I'm not sure, but it seems otherwise to me. Consider the following example:

my $_ = '1'; /(.)/; print "before: \$1 = $1\n"; for (2..4) { print "\$_ = $_\n"; print "first: \$1 = $1\n"; /(3)/; print "second: \$1 = $1\n"; } continue {} print "after: \$1 = $1\n";

Which produces

before: $1 = 1 $_ = 2 first: $1 = 1 second: $1 = 1 $_ = 3 first: $1 = 1 second: $1 = 3 $_ = 4 first: $1 = 1 second: $1 = 1 after: $1 = 1

At least it is not the case that once a capture variable is set it can't go away by going out of scope. Not only does $1 of the inner scope go away after the loop is completed, but the previous value of the outer scope's $1 remains, unaltered by $1 having been set in the inner scope. And the $1 of the inner scope doesn't even persist from one iteration of the loop to the next. While this effect could be achieved by localization of a global variable, perlre says explicitly that the numbered match variables are dynamically scoped. And my understanding of dynamically scoped is that they are lexical variables, not localized global variables. Of course, I could be was wrong and confused dynamic and lexical scoping. , as could the documentation. I haven't looked at the implementation.


In reply to Re^2: Problem with regexp or saved match variable. by ig
in thread Problem with regexp or saved match variable. by steve077

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.