in reply to Re^3: A bug in Perl regex(?)
in thread A bug in Perl regex(?)
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.
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
|
|---|