How about if you do a two-stage process of elimination: (please see the 'Update' first).
while( <IFILE> ) { next unless m/^[CKMPSWY]/; print OFILE unless /^(?:CP|K[LM]|ME|P[AM]|S[LZ]|WX|YZ)XX1/; }
This sort of "optimization" is highly sensitive to the type of data, however, if lines starting with [CKMPSWY] are sparse, it will reject non-matches much faster.
Update: Uggh, my logic is backwards in that snippet. The point is that if you can reject non-matches earlier, with fewer cycles, you save a little time.
I also wanted to mention the "print late" philosophy. If you're IO bound, you might be better off storing a few dozen lines in a scalar and printing just once every few-dozen iterations instead of on every iteration. This will maximize the effectiveness of the OS's buffering.
Dave
In reply to Re: perl performance vs egrep
by davido
in thread perl performance vs egrep
by dba
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |