Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-03-29 12:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found