Anant Gupta <mailto:[email protected]> asked:
> In the foreach loop, without going to the beginning of the loop, i want
> to get the next iteration of data. How do i get it.

You should probably not "slurp" (read in all at once) the file unless you need 
to.

In your particular case reading in line by line is especially useful since this 
would allow you to retrieve the next line from the file handle without having 
to go to the next iteration in the loop.

Eg. (untested & OTTOH though):

my $filename = 'abc.txt';

open( my $file, '<', $filename ) or die "Can't open '$filename': $!";

while( my $line = <$file> ){
  if($line =~ m/something/){
    if( defined( $line = <$file> ) ){
      # do something with new line
    } else {
      # handle EOF here
    }
  }
}


HTH,
Thomas

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


Reply via email to