in reply to Searching pattern in 400 files and getting count out of each file
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Searching pattern in 400 files and getting count out of each file
by space_monk (Chaplain) on Nov 08, 2012 at 11:30 UTC | |
by Rita_G (Initiate) on Nov 09, 2012 at 06:52 UTC | |
by Athanasius (Archbishop) on Nov 09, 2012 at 12:52 UTC |