in reply to Is there a way to read a file backwards?

Take a look at File::ReadBackwards.

From the docs:

$bw = File::ReadBackwards->new( 'log_file' ) or die "can't read 'log_file' $!" ; while( defined( $log_line = $bw->readline ) ) { print $log_line ; }

Replies are listed 'Best First'.
RE: Re: Is there a way to read a file backwards?
by Anonymous Monk on Jul 31, 2000 at 08:11 UTC
    You could also do it manually(without the module).
    <code>
      $line_count=-1;
    
      while(<>)
      {  $line_count++;  }
    
      print "There are $line_count lines in the file.";
    
      # To change the line number for the current filehandle
      # set the '$.' var to desired # not to exceed $line_count
    <code>
    
      I don't think that setting $. will help you much. This variable is incremented on each read, but it isn't used by perl to track its place in the file. In fact, $. isn't even file specific. I quote from the Camel Book,
      The current input line number of the last filehandle that was read. An explicit close on the filehandle resets the line number. Since <> never does an explicit close, line numbers increase across ARGV files