jarich has asked for the wisdom of the Perl Monks concerning the following question:
The basic structure of the code I'm working on is this:
while (<>) { ..... if(/...../) { ... } elsif(/...../) { ... } ..... # and a bunch more regexps increment_counters(...); ..... } sub increment_counters { .... if(/...../) { ..... next; # note that this nexts the above loop } if(/..../) { .... next; } ...... }
My questions are the following. None of the regular expressions here are precompiled. Is there a way to precompile them without creating more variables eg:
or rather something like that, as that won't work. Alternately, if I precompile the expressions as a variable:if( qr/..../ )
will the precompilation disappear once the variable goes out of scope? I'm assuming it will but wouldn't that ruin the point of precompiling? Is my only option to dump these regexps into a hash or make the global etc?my $date = qr/...../; if(m/$date/) { ..... }
I want to optimise this code because I'm processing files with roughly 9 million lines in them (and taking 3-4 days to do each one). We've done a lot of optimisation already.
Perhaps I should inline the increment_counters function.. any ideas on whether that would help? I'm spending 48.7% of my time in this function.
jarich
Edit ar0n -- Added a ReadMore tag
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Precompiled Reg Exps
by perlplexer (Hermit) on Apr 26, 2002 at 00:38 UTC | |
|
Re: Precompiled Reg Exps
by Fletch (Bishop) on Apr 26, 2002 at 02:26 UTC | |
|
Re: Precompiled Reg Exps
by pdcawley (Hermit) on Apr 26, 2002 at 06:20 UTC |