Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
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

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 fire pops...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2017-11-18 09:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (277 votes). Check out past polls.

    Notices?