in reply to advancing in file read

Depending on the size of the file (and your needs) you could read the entire file into an array, and then loop through the array...

Replies are listed 'Best First'.
Re^2: advancing in file read
by ikegami (Patriarch) on May 16, 2010 at 19:40 UTC
    How is that different than what he is doing now (reading the entire file into a list, then looping through the list)? Your solution is incomplete.
      You are correct; thanks.
      1. Read the file into an array without processing the content.
      2. Set an index to 0
      3. Process the contents of the current index of the array. If said contents require information on the next line, refer to the (index + 1) element of the array.
      4. Increment the index by 1 or 2, as appropriate.
        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; ... } ... }