Greetings fellow monks,

Is there a reasonably simple (i.e. no outside modules) and inexpensive way to simulate UNIX's "tail" in core Perl? Here's my situation: I've got a text file that I know over time is going to get really large. I'd like to be able to cheaply and quickly grab the last 10 (or some other specific number) of lines from the file. Obviously, I could just read in the file or just while through it until I get to the end, but I'm looking for something a little nicer.

Part Two: If finding a tail-like solution is fairly easy, the next step is to say, "Give me lines 1034 through 1047 of the file." Again, the easy solution would be just to parse through the file or something. But I'm looking for something cheaper.

Thanks in advance. Also, I'm cool with accepting that there is no solution without modules or lots of code, but I'm just hopefull... :)

-Gryphon.


In reply to Simulating UNIX's "tail" in core Perl by gryphon

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.