On Nov 19, 2007, at 3:38 PM, Shuaib Zahda wrote:

> I was trying to find a method to read only the last line of a file. I
> checked the the documentation and there is no such method.
> Beside reading line after line and checking the the eof method. Is  
> there
> any faster or shorter way to do that.

In Perl there's File::ReadBackwards:

   http://search.cpan.org/~uri/File-ReadBackwards-1.04/ReadBackwards.pm

The idea is that you put the file object in binmode and pick a chunk  
of bytes towards the end of the file using for example

   file.seek(-chunk_size_in_bytes, IO::SEEK_END)

and see whether the last (or last-but-one) line separator is there. If  
it is not, step a bit backwards and try again.

-- fxn