how to read last row in a datafile ?

Discussion in 'Perl Misc' started by Jack, Oct 2, 2006.

  1. Jack

    Jack Guest

    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
    Jack, Oct 2, 2006
    #1
    1. Advertising

  2. Jack

    Paul Lalli Guest

    Paul Lalli, Oct 2, 2006
    #2
    1. Advertising

  3. 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
    Bart Van der Donck, Oct 2, 2006
    #3
  4. Jack

    Ted Zlatanov Guest

    On 2 Oct 2006, 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
    Ted Zlatanov, Oct 2, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Zulander

    XmlDataSource, datafile to a variable

    Zulander, Aug 23, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    2,019
    Kevin Jones
    Aug 24, 2006
  2. Replies:
    3
    Views:
    345
    Richard Herring
    Mar 2, 2006
  3. rsk

    Problem in reading datafile

    rsk, Sep 6, 2007, in forum: C Programming
    Replies:
    3
    Views:
    269
    Chris Dollin
    Sep 6, 2007
  4. D
    Replies:
    0
    Views:
    197
  5. Karel

    Opening new window with datafile

    Karel, Feb 9, 2005, in forum: Javascript
    Replies:
    5
    Views:
    99
    Randy Webb
    Feb 10, 2005
Loading...

Share This Page