Indeed if you worry about performance you should probably not use a shell call of "grep", but use the internal perl grep command.
Why not just simply open each file one at a time?
open my $p, "< ". shift @ARGV or die "could not open pattern file: $!"; my @pattern = map { chomp; qr/$_/ } <$p>; for my $filename (@ARGV) { open my $f, "< $filename" or die "could not open $filename: $!"; my @lines = <$f>; for my $pattern (@pattern) { printf "%s has %d matches for pattern %s\n", $filename, scalar(grep $pattern, @lines), $pattern; } }
NB. This post was edited several times.
In reply to Re: Searching pattern in 400 files and getting count out of each file
by grondilu
in thread Searching pattern in 400 files and getting count out of each file
by Rita_G
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |