in reply to A bug in Perl regex(?)
NOTE: because you are using a quantifier on this capture, only the LAST repetition of the captured pattern will be stored in [$2]On the first time through, \w+ grabs both letters are stores them in $2, and prints ab as expected. It then sees the repetition at the end, shifts the pointer for the second buffer to the second repetition (what would be $4 in my unrolled version). This means when the first attempt fails and you grab a on your second attempt, $2 doesn't point there anymore - it points to the second buffer in the second iteration.
I think (though this is subject to argument) that the correct behavior should not be what you claim, but should be
since the final $2 buffer is not populated until your second iteration. In the end, it just goes to emphasize perlreftut's warning:$2 not defined $2 not defined $2=b
Be warned that this feature is considered experimental, and may be changed without notice.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: A bug in Perl regex(?)
by ikegami (Patriarch) on Feb 18, 2011 at 16:21 UTC | |
by kennethk (Abbot) on Feb 18, 2011 at 17:44 UTC | |
by ikegami (Patriarch) on Feb 18, 2011 at 20:02 UTC | |
by Serge314 (Acolyte) on Feb 19, 2011 at 08:59 UTC |