Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Performing a tail(1) in Perl (reading the last N lines of a file)

by KM (Priest)
on Apr 25, 2002 at 17:03 UTC ( #162040=note: print w/ replies, xml ) Need Help??


in reply to Performing a tail(1) in Perl (reading the last N lines of a file)

What did you find wrong with the Perl Power Tools version of tail(1) that you wanted to (partially) recreate it? Looks like you had a fun exercise though :)

Cheers,
KM


Comment on Re: Performing a tail(1) in Perl (reading the last N lines of a file)
Re:x2 Performing a tail(1) in Perl (reading the last N lines of a file)
by grinder (Bishop) on Apr 25, 2002 at 17:14 UTC
    I'm aware of the PPT project, but to my mind they are shell tools, and do not have a modul(e|ar) interface so you can't "embed" them in your script, you have to backtick them, just like the original tail(1). I could be wrong about that though.

    (A few moments later) hmmm no, it still looks like you can only run it as a child process, which is what I wanted to avoid. There is a sub named print_tail, which, according to its comments "Prints the tail of a file according to the options passed on the command line". I don't see a function that returns an array of scalars, which is what I was after.


    print@_{sort keys %_},$/if%_=split//,'= & *a?b:e\f/h^h!j+n,o@o;r$s-t%t#u'
      But, it does what you want (plus more). You sort of took a spoke of a wheel, and rewrote the spoke :) Your code isn't any more modular than the one from PPT. Point being that there is good code written to do what you wanted, but instead of using it (embedding what you needed), or modularizing it you redid it. I'm not griping, but when you show a lot of benchmarks you obviously took time to do it multiple ways to see which is fastest (fast ne best) as opposed to taking the time to make a current wheel more useful. But, like I said before, seems like you had a good exercise :)

      Cheers,
      KM

Unable to find this thread named: Performing a tail(1) in Perl (reading the last N lines of a file)
by dpraba3 (Initiate) on Jul 17, 2008 at 23:27 UTC
    I'm not able to find this thread -the Perl Power Tools version of tail(1).Could some one please repost it?I want to find how to print last n lines in the most efficient way. I should not read entire file to print the last n lines.

      CPAN has it: tail in the ppt distribution. Also, a simple Google search for perl tail will also bring you to CPAN. Do some work yourself.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (10)
As of 2014-08-29 22:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (289 votes), past polls