Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

I've just got a warning from CPAN testers about one of my modules failing to compile under Perl 5.8.4.

The code, in its simplest form, is almost the same that you could get from perlre:

#!/usr/bin/perl -w use strict; our $re = qr{ \( (?: (?> [^()]+ ) | (??{ $re }) )* \) }x;

This code used to work fine from Perl 5.6.1 to 5.8.3

Under the latest version (5.8.4) it breaks as follows:

Variable "$re" is not imported at (re_eval 1) line 2.
Global symbol "$re" requires explicit package name at (re_eval 1) line 2.
Compilation failed in regexp at line 12.

If I want to compile the same code, now, I need to either enclose the offending regex inside a "no strict 'vars'" block or call the variable with a package name:

#!/usr/bin/perl -w use strict; our $re = qr{ \( (?: (?> [^()]+ ) | (??{ $main::re }) )* \) }x;

With this correction the code compiles.

Proof of concept:

$_ = 'aa bb (cc (dd) ee) ff '; # wanting ^----------^ print "$1\n" while m/($re)/g ; __END__ __OUTPUT__ (cc (dd) ee)

I wonder, though, if the "correct" behavior was the previous one or the current one.

I mean, I can't use this code with a variable declared as "my $re = qr/ ....", because by the time it gets embedded inside the regex, its value is still undefined. The example in perlre is actually using a global variable, which won't work under "strict" rules.

Any thoughts?

update (1)
The previous behavior was "correct" in the technical sense. The compiler wouldn't complain and it would produce the expected results.

I remember trying the my $re; $re = qr//; arrangement in an earlier version of Perl, and discarding it because it wouldn't work. I tried to replicate the failing behavior but I can't isolate a simple case, even though my module (Chess::PGN::Parse) will work as expected with a complete package name, but it will break under this syntax.

My decision of using "our" came after seeing that TheDamian's Regexp::Common was implemented without "use strict" at all. I should have looked at it again after Abigail took over the module.

update (2)
Actually, it will also work with our $re; $re = qr/ ... $re.../; (Thanks dragonchild).

update (3)
I submitted a patched module to CPAN, and now (26-May-2004) the testers reports look much better!

 _  _ _  _  
(_|| | |(_|><

In reply to Broken compatibility for recursive regex in Perl 5.8.4 by gmax

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, 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, 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.
  • Log In?

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

    How do I use this? | Other CB clients
    Other Users?
    Others exploiting the Monastery: (4)
    As of 2019-12-11 00:56 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found