in reply to faster way to grep
What do you get when you add:
print "@ids\n"; print "@files\n";
to your code?
This doesn't seem like the right approach to me:
foreach my $id (@ids) { foreach my $fasta (@files) { open my $fh, '<', $fasta or die "can not open file $fasta: $!" +; while (<$fh>) { print if /$id/; } close $fh; } }
If there are 5 ids and 10 files, that code will open and close each file 5 times. How about something like this:
my $pattern = join '|', @ids; print grep {/$pattern/} <>;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: faster way to grep
by dsheroh (Monsignor) on Mar 16, 2010 at 11:19 UTC |