|Keep It Simple, Stupid|
Broken compatibility for recursive regex in Perl 5.8.4by gmax (Abbot)
|on May 24, 2004 at 23:10 UTC||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:
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 testrecursive.pl 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:
With this correction the code compiles.
Proof of concept:
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.
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.
_ _ _ _ (_|| | |(_|>< _|