Its already been offered what to do to fix it. However, I have a suggestion to make it go faster. Instead of using alternation within the regex, use Perl's logical or outside of it. That is:
while(/(regex1)/gi || /(regex2)/gi || /(regex3)/gi)
You need the /g in this example even if you don't expect the same regex to appear on the same line multiple times. The advantage to this example is that it significantly(well,depending on the regex) cuts down on the amount of backtracking that is neccessary by the NFA machine. You could also take that out of the while loop, and do this:
while(<file>) {
(/(regex1)/i || /(regex2)/i || /(regex3)/i) && f($1);
}
(Only do this, though, if you only expect one regex per line)
The advantage to this situation is that, if needed, you can call specific functions(or do specific actions) on a per regex level. E.g., :
while(<file>) {
#put a while around the regexes if there is multiple
#regexes per line; aslo add a /g
( (/(regex1)/i && doSomethingForRegex1($1)) ||
(/(regex2)/i && doSomethingForRegex2($1)) ||
(/(regex3)/i && doSomethingForRegex3($1)) ) &&
still_do_a_general_func_if_needed($1);
}
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.