The content below is stored in a string and parsed
with the regular expression following it:
$str = <<EOFSTR;
content
content
<%start_wibble XXX%>
content
content
<%start_flub YYY%>
content
content
content
<%end_flub%>
content
content
<%end_wibble%>
content
content
EOFSTR
$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?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.