in reply to look-ahead greed changed between perl releases?

As a follow-up to my post above where I pointed to the documented bug fix, here's a short script (with simplified data and regex) which demonstrates what's happening before and after the 5.14.0 fix.

#!/usr/bin/env perl use 5.010; use strict; use warnings; say "Perl Version: $^V"; my $test_string = 'www xxx-A-B-C-D yyy zzz-E-F-G-H'; my $re = qr< \S+ (?: [A-Z]- ){2,} [A-Z] \b >x; say '=' x 60, "\n*** NO look-ahead ***\n", '=' x 60; my $no_look_ahead_test_string = $test_string; while ($no_look_ahead_test_string =~ /($re)/gp) { say "Prematch: '${^PREMATCH}'"; say "Match: '${^MATCH}'"; say "Postmatch: '${^POSTMATCH}'"; say '-' x 60; } say '=' x 60, "\n*** USING look-ahead ***\n", '=' x 60; my $look_ahead_test_string = $test_string; while ($look_ahead_test_string =~ /(?=$re)/gp) { say "Prematch: '${^PREMATCH}'"; say "Match: '${^MATCH}'"; say "Postmatch: '${^POSTMATCH}'"; say '-' x 60; }

The nearest versions I have to 5.14.0 are 5.12.3 and 5.14.2.

Here's the 5.12.3 output:

Perl Version: v5.12.3 ============================================================ *** NO look-ahead *** ============================================================ Prematch: 'www ' Match: 'xxx-A-B-C-D' Postmatch: ' yyy zzz-E-F-G-H' ------------------------------------------------------------ Prematch: 'www xxx-A-B-C-D yyy ' Match: 'zzz-E-F-G-H' Postmatch: '' ------------------------------------------------------------ ============================================================ *** USING look-ahead *** ============================================================ Prematch: 'www ' Match: '' Postmatch: 'xxx-A-B-C-D yyy zzz-E-F-G-H' ------------------------------------------------------------ Prematch: 'www xxx-A-B-C-D yyy ' Match: '' Postmatch: 'zzz-E-F-G-H' ------------------------------------------------------------

Here's the 5.14.2 output:

Perl Version: v5.14.2 ============================================================ *** NO look-ahead *** ============================================================ Prematch: 'www ' Match: 'xxx-A-B-C-D' Postmatch: ' yyy zzz-E-F-G-H' ------------------------------------------------------------ Prematch: 'www xxx-A-B-C-D yyy ' Match: 'zzz-E-F-G-H' Postmatch: '' ------------------------------------------------------------ ============================================================ *** USING look-ahead *** ============================================================ Prematch: 'www ' Match: '' Postmatch: 'xxx-A-B-C-D yyy zzz-E-F-G-H' ------------------------------------------------------------ Prematch: 'www x' Match: '' Postmatch: 'xx-A-B-C-D yyy zzz-E-F-G-H' ------------------------------------------------------------ Prematch: 'www xx' Match: '' Postmatch: 'x-A-B-C-D yyy zzz-E-F-G-H' ------------------------------------------------------------ Prematch: 'www xxx' Match: '' Postmatch: '-A-B-C-D yyy zzz-E-F-G-H' ------------------------------------------------------------ Prematch: 'www xxx-' Match: '' Postmatch: 'A-B-C-D yyy zzz-E-F-G-H' ------------------------------------------------------------ Prematch: 'www xxx-A' Match: '' Postmatch: '-B-C-D yyy zzz-E-F-G-H' ------------------------------------------------------------ Prematch: 'www xxx-A-B-C-D yyy ' Match: '' Postmatch: 'zzz-E-F-G-H' ------------------------------------------------------------ Prematch: 'www xxx-A-B-C-D yyy z' Match: '' Postmatch: 'zz-E-F-G-H' ------------------------------------------------------------ Prematch: 'www xxx-A-B-C-D yyy zz' Match: '' Postmatch: 'z-E-F-G-H' ------------------------------------------------------------ Prematch: 'www xxx-A-B-C-D yyy zzz' Match: '' Postmatch: '-E-F-G-H' ------------------------------------------------------------ Prematch: 'www xxx-A-B-C-D yyy zzz-' Match: '' Postmatch: 'E-F-G-H' ------------------------------------------------------------ Prematch: 'www xxx-A-B-C-D yyy zzz-E' Match: '' Postmatch: '-F-G-H' ------------------------------------------------------------

[In case you were wondering, I'm using perlbrew which made it easy to switch versions between runs. Editing the shebang line or calling the script with different paths to perl will work just as well.]

-- Ken