To start with if you do
and then latermy $RE = join '|', <RECORDS>;
for every test, Perl will have to re-compile your pattern every time. It is much better to pre-compile the pattern, by doing/$RE/;
and then latermy $RE = join '|', <RECORDS>; my $compiled_RE = qr/$RE/;
In that case you only pay the compilation cost once./$compiled_RE/;
Even better is it to use a module such as Regexp::Assemble which can automatically compile for you a more efficient regex. Cutting down on the number of alternations will lead to a faster regex. I tried this in a program of mine and by using Regexp::Assemble managed to get a 30% speed increase when using real world data.
CountZero
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
In reply to Re: Not sure what I am doing wrong
by CountZero
in thread Not sure what I am doing wrong
by learningperl01
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |