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


In reply to Re: look-ahead greed changed between perl releases? (before and after the fix) by kcott
in thread look-ahead greed changed between perl releases? by raygun

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.