in reply to Re: Is there a way to read a file backwards?
in thread Is there a way to read a file backwards?

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>
  • Comment on RE: Re: Is there a way to read a file backwards?

Replies are listed 'Best First'.
RE: RE: Re: Is there a way to read a file backwards?
by Adam (Vicar) on Jul 31, 2000 at 20:34 UTC
    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