Hi,

every outer loop you are reading all the $AFILE lines. From the second loop the 
Descriptor points to the end. If you want to work this way you seed to lseek to 
the begin. 
If you you have a variable that holds the file contents you can do the 
following:

my @lines = <$AFILE>;
foreach my $prime_id ( @id_hits ) {
     foreach my $line( @lines ) {
         if ( $line =~ /$prime_id/ ) {
             print "$line\n";
             next;
         }
     }
}


Hope that helps

Yaron Kahanovitch
----- Original Message -----
From: "Robert Hicks" <[EMAIL PROTECTED]>
To: beginners@perl.org
Sent: Tuesday, May 8, 2007 4:39:12 PM (GMT+0200) Auto-Detected
Subject: Re: looping through a file

I decided to back up a bit and try a more simple routine. I have the 
array @id_hits populated and I can search the log for the line and print 
it. The problem is it only finds the first match and that is it.

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

Do I need to pass it back to the foreach somehow?

Robert

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to