in reply to (??{ code }) versus (?PARNO) for recursive regular expressions
I can of course work with this limitation, but it's not completely satisfying since it was not necessary before (don't remember version of perl, 5+years ago)
That's not true. Variable declarations have always taken effect in the statement following the one containing the declaration. Perhaps you weren't using lexical ("my") variables (or strict) "5+ years ago".
Unrelated, don't use lexicals from outside the pattern inside of (?{ ... }), (??{ ... }) and anything similar.
$ perl -wE' sub f { my $x = $_[0]; "" =~ /(??{ say $x; "" })/; } f("abc"); f("def"); ' Variable "$x" will not stay shared at (re_eval 1) line 1. abc abc
Use a package variable instead.
$ perl -wE' sub f { local our $x = $_[0]; "" =~ /(??{ say $x; "" })/; } f("abc"); f("def"); ' abc def
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: (??{ code }) versus (?PARNO) for recursive regular expressions
by wind (Priest) on Mar 25, 2011 at 22:41 UTC | |
by ikegami (Patriarch) on Mar 25, 2011 at 22:47 UTC | |
by wind (Priest) on Mar 25, 2011 at 23:32 UTC | |
by ikegami (Patriarch) on Mar 25, 2011 at 23:46 UTC | |
by wind (Priest) on Mar 26, 2011 at 00:45 UTC | |
|
In Section
Seekers of Perl Wisdom