in reply to Perl's POD's description of the use of capturing special variables.
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
|
|---|