in reply to Re^2: Read the last line in a text file
in thread Read the last line in a text file

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`;

Replies are listed 'Best First'.
Re^4: Read the last line in a text file
by ikegami (Patriarch) on Aug 22, 2008 at 15:04 UTC
    While it does read the entire file, and while it keeps an index of every line in memory, it doesn't keep the entire file in memory.
Re^4: Read the last line in a text file
by massa (Hermit) on Aug 22, 2008 at 12:54 UTC
    I stand corrected, you are obviously right. This should work without the memory overhead:
    print do { my $l; $l = $_ while <FILE>; $l }
    []s, HTH, Massa (κς,πμ,πλ)