Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
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
Replies are listed 'Best First'.
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 chilling in the Monastery: (6)
As of 2015-07-29 07:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (260 votes), past polls