The value of the special capturing variables will be undef in the event of no match within current scope, or the value of the most recent successful match's capture in the current scope even if there has been a subsequent failed match.

As others have pointed out, the wording here is far from optimal. My problem, however, is that it does not explain the following (but neither does the existing POD, as far as I understand it, so don't take this personally ;):

while ( <DATA> ) { /^([A-Z]+)$/ or print "Line $.: No match: $1\n"; } __DATA__ FOO 1234 XYz

Output:

Line 2: No match: FOO Line 3: No match: F

While for Line 2, $1 is, as expected, "the value of the most recent successful match's capture", why oh why is $1 not still 'FOO' (or undef) for Line 3??

dave


In reply to Re: Perl's POD's description of the use of capturing special variables. by Not_a_Number
in thread Perl's POD's description of the use of capturing special variables. by davido

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.