Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

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?

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (2)
As of 2015-11-28 09:52 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (741 votes), past polls