Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Usage of grep on a file

by rafl (Friar)
on Apr 07, 2006 at 07:36 UTC ( #541814=note: print w/ replies, xml ) Need Help??


in reply to Usage of grep on a file

First of all, use qr// to precompile your patterns:

my @compiled_patterns = map { qx/$_/ } @matcharray;

Also don't slurp the file into an array. Use something more memory-efficient:

OUTER: while (my $line = <$file>) { INNER: for my $pattern (@compiled_patterns) { print $line, last INNER if $line =~ $pattern; } }

Cheers, Flo


Comment on Re: Usage of grep on a file
Select or Download Code
Re^2: Usage of grep on a file
by jwkrahn (Monsignor) on Apr 07, 2006 at 09:51 UTC
    Your text says "qr//" but your code says "qx//". Using qx// in this situation could prove very interesting! :-)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://541814]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (9)
As of 2014-07-28 13:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (198 votes), past polls