in reply to Re^3: advancing in file read
in thread advancing in file read

So
my @array = <$fh>; for (my $i=0; $i<@array; ++$i) { my $line = $array[$i]; ... if (...) { defined( my $next_line = $array[++$i] ) or die; ... } ... }

It's simpler just doing

while (my $line = <$fh>) { ... if (...) { defined( my $next_line = <$fh> ) or die; ... } ... }

Replies are listed 'Best First'.
Re^5: advancing in file read
by apl (Monsignor) on May 17, 2010 at 10:34 UTC
    It is if the same processing must be applied to every line in the file, even if said line was the second line of an earlier piece of processing.

    Requiring the file be read at the top of the loop denies you the ability to reprocess the second line. The OP had said

    And is there a way to advance the file handle so it doesn't re-read the next line in the foreach loop?

      It's my understanding that the OP doesn't want to re-read the line because he doesn't want to reprocess it, not for efficiency purposes.