Re: Using an array to search a text file



"PL" == Paul Lalli <mritty@xxxxxxxxx> writes:

PL> foreach my $prime_id ( @id_hits ) {
PL> while ( my $line = <$AFILE> ) {
PL> print $line if $line =~ /$prime_id/ ;
PL> }
PL> seek($AFILE, 0, 0); #rewind file when exhausted
PL> }

i don't know why no one has told you to invert the order of the loops
and scan the file once and the ids inside that. no seek is needed and it
will be much faster as the file is read in only one time.

while ( my $line = <$AFILE> ) {
foreach my $prime_id ( @id_hits ) {
print $line if $line =~ /$prime_id/ ;
}
}

uri

--
Uri Guttman ------ uri@xxxxxxxxxxxxxxx -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
.