in reply to Re: Simulating UNIX's "tail" in core Perl
in thread Simulating UNIX's "tail" in core Perl

Please pardon my extreme newbie-ness on this one. I read over the seek stuff and found that example yesterday, but I can't figure out how it works. Can someone explain (in very small words so I'll be sure to understand) how this will let me grab lines 1027 to 1031 from a 2500+ line file? Thanks. (Again, my appologies if I'm being a complete dunce.)

-Gryphon.

Replies are listed 'Best First'.
(tye)Re: Simulating UNIX's "tail" in core Perl
by tye (Sage) on Mar 08, 2001 at 01:01 UTC

    It won't.

    There are no shortcuts for finding the 1027th line of a text file containing arbitrary lines of arbitrary length. Now, if you want the last 100 lines, then seek can be a very effective short cut.

    If the lines are of fixed length or you can identify the desired lines by something other than sequence (for example, if the text of the lines contain line numbers), then you can probably come up with shortcuts that don't involve just reading all of the lines and looking for and counting the newlines.

            - tye (but my friends call me "Tye")