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

The thing as, as I understand the documentation of perlre, [use strict; our $x = qr/... (??{ $x }) .../ ] should be allowed

You're using a variable ($x) you haven't declared yet. It's a strict error just like

$ perl -e'use strict; our $x = $x;' $

huh... what? I guess I was wrong. our declarations take effect immediately. I don't see why «our $x = $x;» and «our $x = qr/(??{ $x })/;» can behave differently. It would seem there's a bug here.

Replies are listed 'Best First'.
Re^6: (??{ code }) versus (?PARNO) for recursive regular expressions
by wind (Priest) on Mar 26, 2011 at 00:45 UTC

    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.

      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.