develooper Front page | perl.perl5.porters | Postings from February 2003

Re: [perl #20683] [fix] /(??{$x})/ ignore any changes made to $x

Thread Previous | Thread Next
From:
perl5-porters
Date:
February 22, 2003 14:58
Subject:
Re: [perl #20683] [fix] /(??{$x})/ ignore any changes made to $x
Message ID:
b38p17$7ok$1@post.home.lunix
In article <20030222192221.GA10431@ratsnest.hole>,
	Enache Adrian <enache@rdslink.ro> writes:
> $ perl -le '$_ ="1234"; $x=1; s/(??{$x})/$x++,z/ge; print $_'
> 
> that should print zzzz but prints z234.
> 
> The return value of a (??{ .. }) construct is compiled to a regexp before
> being matched. In order to avoid re-compiling it every time, it is
> cached by assigning 'r' magic to the variable which holds the return value
> - with the  mg_obj field pointing to the compiled regular expression.
> (see regexec.c:2864)
> 
> When the value of that variable is changed in any way, constructs like
> (??{ ..;$var}) will still use the stale regular expression.
> 

This seems a case where the problem can be solved by simply dropping
this optimization. If the value wasn't supposed to change all the 
time, the user would almost certainly have written s/$p// instead of
s/(??{$p})//, so i think this optimization is not worth it (ok, someone
might do it to set $^R and $^N)

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About