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:
hv
Date:
February 23, 2003 18:04
Subject:
Re: [perl #20683] [fix] /(??{$x})/ ignore any changes made to $x
Message ID:
200302240206.h1O26cC11762@crypt.compulink.co.uk
Enache Adrian <enache@rdslink.ro> wrote:
:$entremets = "a";
:$appero = "b";
:
:$/=\4096;
:
:while(<>) {
:	$a = not $a;
:	print if /(??{
:		$a ? $entremets : $appero;
:	})/
:}

For what it's worth, I've written code very like this to add
assertions to regexps, and always did it like this:

$true = qr/(?=)/;
$false = qr/(?!)/;
...
m{
  match stuff
  (??{ ok() ? $true : $false })
  match more
}x;

The main reason for doing that was to get around reentrancy problems
(coredumps when trying to compile re's during a match); it appears
that with 5.8.0 it is now safe to do:
  perl -wle '
    $_="";
    for $p (0,1,0,1) {
      print /(??{ $p ? qr{(?=)} : qr{(?!)} })/ ? "match" : "no match";
    }'

Precompiling the returned patterns bypasses the (obviously buggy)
optimisation altogether. I think it might make most sense to remove
the optimisation and document this as the recommended approach.

Hugo

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