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

Re: regexp iteration limits

Thread Previous | Thread Next
From:
Zefram
Date:
February 12, 2009 00:21
Subject:
Re: regexp iteration limits
Message ID:
20090212081959.GD2263@fysh.org
David Nicol wrote:
>$ perl -lwe '$a="xyzt"x10000; utf8::upgrade($a);print $a =~
>/\A(?>(?>[a-z])*)*\z/ ? "ok" : "bug"'
>ok

The form you give here has very inefficient behaviour for a non-matching
string.  Also, if the inner expression is more complex (e.g., (?>X?[a-z])
it generates the "recursion limit" warning.  So it's better done as

	/\A(?>(?>[a-z]){1,32766})*\z/

I considered this class of workaround.  It works for non-backtracking
expressions, and effectively squares the iteration limit.  It's a great
practical improvement, but still most unsatisfying that it still has
a limit that is smaller than achivable address spaces.  One can apply
multiple layers of quantification to get a still higher iteration limit,
but then I don't know how many to do.

So, it's an option.  I'm happier using this as a local hack than as a
public solution.

-zefram

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