Re: Using an array to search a text file
- From: Paul Lalli <mritty@xxxxxxxxx>
- Date: 8 May 2007 13:01:54 -0700
On May 8, 3:52 pm, Uri Guttman <u...@xxxxxxxxxxxxxxx> wrote:
"PL" == Paul Lalli <mri...@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/ ;
}
}
Probably because that would rather drastically alter the order of the
output.... I'm making the assumption that the OP knows in what order
he wants the output. That's every line that contains the first
$prime_id, then every line that contains the second $prime_id, etc.
You've reversed that to the first line once for each $prime_id it
contains, then the second line once for each $prime_id it contains,
etc.
Paul Lalli
.
- 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
- Re: Using an array to search a text file
- From: Uri Guttman
- Using an array to search a text file
- Prev by Date: Re: Action before clicking a link
- Next by Date: Re: Click link to go to routine
- Previous by thread: Re: Using an array to search a text file
- Next by thread: How to Run/Convert(?) Script Built on 5.8.4 to 5.004
- Index(es):