how to read last row in a datafile ?

J

Jack

Hi there, does anyone know how to capture the last row in a datafile
into a variable without having to read through each record of the
entire file ?

Thank you,

Jack
 
B

Bart Van der Donck

Jack said:
Hi there, does anyone know how to capture the last row in a datafile
into a variable without having to read through each record of the
entire file ?

On UNIX (and some Windows versions):

my $lastline = `tail -1 /path/to/file.txt`;
 
T

Ted Zlatanov

On UNIX (and some Windows versions):

my $lastline = `tail -1 /path/to/file.txt`;

That should be /usr/bin/tail or whatever's appropriate on the system.
Calling unqualified programs is a dangerous practice.

Ted
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,263
Messages
2,571,064
Members
48,769
Latest member
Clifft

Latest Threads

Top