Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > how to read last row in a datafile ?

Reply
Thread Tools

how to read last row in a datafile ?

 
 
Jack
Guest
Posts: n/a
 
      10-02-2006
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

 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      10-02-2006
Jack wrote:
> 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 ?


Download and install the File::ReadBackwards module from CPAN...

http://search.cpan.org/~uri/File-Rea...adBackwards.pm

Paul Lalli

 
Reply With Quote
 
 
 
 
Bart Van der Donck
Guest
Posts: n/a
 
      10-02-2006
Jack wrote:

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

--
Bart

 
Reply With Quote
 
Ted Zlatanov
Guest
Posts: n/a
 
      10-02-2006
On 2 Oct 2006, http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

Jack wrote:
>> 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`;


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

Ted
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
name = upload['datafile'].original_filename Abder-Rahman Ali Ruby 2 09-20-2010 12:42 PM
Problem in reading datafile rsk C Programming 3 09-06-2007 02:53 PM
XmlDataSource, datafile to a variable Zulander ASP .Net 2 08-24-2006 07:35 AM
Two questions...first, outputting strings from a datafile, and string addition... snow.carriers@gmail.com C++ 3 03-02-2006 04:01 PM



Advertisments