in reply to Re^5: (??{ code }) versus (?PARNO) for recursive regular expressions
in thread (??{ code }) versus (?PARNO) for recursive regular expressions

Thank you for the sanity check. I ran your above statements on strawberry perl v5.12.1

> perl -e"use strict; our $x = $x;" > perl -e"use strict; our $x = qr/(??{ $x })/;" Variable "$x" is not imported at (re_eval 1) line 2. Global symbol "$x" requires explicit package name at (re_eval 1) line +2. Compilation failed in regexp at -e line 1. > perl -e"use strict; my $x = qr/(??{ $x })/;" Global symbol "$x" requires explicit package name at (re_eval 1) line +2. Compilation failed in regexp at -e line 1.

And on perl v5.10.0 built for i686-linux

$ perl -e'use strict; our $x=$x;' $ perl -e'use strict; our $x=qr/(??{ $x })/;' Variable "$x" is not imported at (re_eval 1) line 2. Global symbol "$x" requires explicit package name at (re_eval 1) line +2. Compilation failed in regexp at -e line 1. $ perl -e'use strict; my $x = qr/(??{ $x })/;' Global symbol "$x" requires explicit package name at (re_eval 1) line +2. Compilation failed in regexp at -e line 1.

However, done on perl v5.8.0 built for i386-linux-thread-multi, I get no strictures errors and the original parsing code works as desired.:

$ perl -e'use strict; our $x = $x' $ perl -e'use strict; our $x = qr/(??{ $x })/;' $ perl -e'use strict; my $x = qr/(??{ $x })/;'

So this change to the way (??{ code }) was validated for strictures changed at least after v5.8.0. Maybe this was done when (?PARNO) was introduced in v5.10.0. I guess that's one way to encourage people to move to a new feature. Gotta say it's still annoying though.

Update: Added data on my declarations using (??{ code }) per ikegami's request.

Replies are listed 'Best First'.
Re^7: (??{ code }) versus (?PARNO) for recursive regular expressions
by ikegami (Patriarch) on Mar 26, 2011 at 02:49 UTC
    Try
    perl -e'use strict; my $x = qr/(??{ $x })/;'
    on 5.8.0 for me please

      I've added the requested information to the previous reply. However, to be thorough, I've run the full script on v5.8.0 as well. When using our $x = qr/(??{ $x })/;, the script works as desired. However, when using my $x = qr/(??{ $x })/;, the script throws no strictures errors, but does throw a warning:

      $ perl rec_regex.pl Use of uninitialized value in substitution iterator at perm.pl line 17 +, <DATA> line 1. <7> { ... } </7> <7> { { } } </7> { <7> { { } } </7> } { <3> { } </3> { <7> { { } } </7> } } <7> { ... } </7>

      Additionally, as you can see it only does the second level of recursion again. Nevertheless, I never used my originally, so just sharing for addition data.

      Also note, I just discovered that the original code DOES work currently if declared with our. It just won't pass strictures validation. Will update my original question with this data soon as I get back from pharmacy. Got a toothache coming on.

        However, when using my $x = qr/(??{ $x })/;, the script throws no strictures errors

        That's the bug I mentioned earlier. The use strict; didn't propagate into the (??{ }). (You're getting the warning because the second $x is the package variable.)

        I'm guessing the behaviour of our $x = qr/(??{ $x })/; changed when they fixed the pragma propagation.

        I'll file a bug report.