http://www.perlmonks.org?node_id=541814


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 (Abbot) 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! :-)