|Perl: the Markov chain saw|
Inefficient regexby Wibble (Beadle)
|on Mar 05, 2003 at 18:17 UTC||Need Help??|
Wibble has asked for the
wisdom of the Perl Monks concerning the following question:
The content below is stored in a string and parsed with the regular expression following it:
$str =~ s/<%start_(.*?)\s*(.*?)\s*%>\n?(.+?)<%end_\1%>\n?/myfunc($2, $3)/segi;
The content is blocked with <%...%> tags, the entry of which is marked
with "<%start_LABEL PARAMETER%>" and the exit of a block is marked
with "<%end_LABEL%>". Whenever the regular expression encounters such
a block it executes myfunc passing in the PARAMETER and the content
enclosed by the block. Myfunc operates on the content passed in
according to the value of the PARAMETER passed.
The code above works fine, but the regular expression can take 30+
seconds when $str contains 500K of characters. Is this normal or
is there something inherently inefficient with my regular expression?
Is it my use of backreferences?