Re: Using an array to search a text file
- From: Uri Guttman <uri@xxxxxxxxxxxxxxx>
- Date: Tue, 08 May 2007 15:52:37 -0400
"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
.
- Follow-Ups:
- Re: Using an array to search a text file
- From: Paul Lalli
- Re: Using an array to search a text file
- References:
- Using an array to search a text file
- From: Robert Hicks
- Re: Using an array to search a text file
- From: Robert Hicks
- Re: Using an array to search a text file
- From: Paul Lalli
- Re: Using an array to search a text file
- From: Robert Hicks
- Re: Using an array to search a text file
- From: Paul Lalli
- Using an array to search a text file
- Prev by Date: Re: parsing a variable length record from a mixed format file
- Next by Date: Re: Action before clicking a link
- Previous by thread: Re: Using an array to search a text file
- Next by thread: Re: Using an array to search a text file
- Index(es):