A successful capture should not be undef. Whether it's documented or not, $1, etc are intended to be available to (?{}) and (??{}) blocks, so they must be set ASAP.
- \w+ matches "ab"
- () sets $2
- Print $2
- Second at \w+ fails to match: backtrack
- \w+ matches "a"
- () sets $2 (This isn't happening)
- Print $2
- \w+ matches "b"
- () sets $2
- Print $2
I do not see a compelling argument for "it should be the last thing matched by those 'physical' parentheses" over my proposal.
If that's true, then you would expect either of
$2=ab # Only thing matched
$2=a # Only thing matched
$2=a # First thing matched
and
$2=ab # Only thing matched
$2=a # Only thing matched
$2=b # Last thing matched
and the code is still buggy as it produces neither.
Clearer bug demonstration:
$ perl -e'"ab" =~ /((\w+)(?{print defined $^N ? "\$^N=$^N\n" : "\$^N n
+ot defined\n"})){2}/;'
$^N=ab
$^N not defined
$^N=b
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.