Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: Print last line in a file

by nehlwyn (Acolyte)
on Aug 22, 2001 at 05:48 UTC ( #106860=note: print w/replies, xml ) Need Help??

in reply to Print last line in a file

Greetings fellow monk ,

You've had several good answers so i had this alternative just for fun and to point at one of the Perl mottos : TIMTOWTDI !!!

Using the same idea to quickly read all the lines but with using the special array @_

open (FILE,"your file"); @_=<FILE>; close(FILE); print pop;

There you go ...

the little one

Replies are listed 'Best First'.
Re (tilly) 2: Print last line in a file
by tilly (Archbishop) on Aug 22, 2001 at 06:22 UTC
    Your open should have an error check as described in perlstyle.

    This is usually done explicitly, but the various shortcuts do so as well. For instance try this:

    @ARGV="your_file"; print((<>)[-1]);
    BTW I really did need both pairs of parens.

      Greetings fellow monk,

      You're dammmn right , sir ... 'was a bit hasty of me ... But fortun'ly , 'had a fellow monk to DWIM(eant) ...;-)

      the little one.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://106860]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (1)
As of 2022-01-25 02:33 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (65 votes). Check out past polls.