ganilmohan has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: Read the last line in a text file
by moritz (Cardinal) on Aug 22, 2008 at 11:38 UTC
        print [<FILE>]->[-1];

        If you mention such things you should also add that it reads the entire file into memory. That might be a bit overkill...

        Another thing that came to my mind, but is restricted to unixy systems:

        my $line = `tail -n1 $file`;

        In addition to the more important observation that moritz made, I can never understand why so often do people seem to feel the need to reference only to dereference like that; i.e. if we assume we do want to slurp the file all at once, then

        print +(<$file>)[-1]; # would do!
        --
        If you can't understand the incipit, then please check the IPB Campaign.
Re: Read the last line in a text file
by Anonymous Monk on Aug 22, 2008 at 12:03 UTC
    A reply falls below the community's threshold of quality. You may see it by logging in.