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

right, it's 10am here in London so i'm not really with it yet. Would someone care to explain this post to me ?

tnx Jorg
  • Comment on Re: Re: Simulating UNIX's "tail" in core Perl

Replies are listed 'Best First'.
Re: Re: Re: Simulating UNIX's "tail" in core Perl
by petral (Curate) on Mar 07, 2001 at 22:28 UTC
    "Give me lines 1034 through 1047 of the file."
    perl -wn000e # -n read file, 000 set $/ (input separator) to n +il # hence, read whole file into $_ '$start = 1034; # number of the line to start printing +at $end = 1047; # number of the line to end printing at $pre = $start - 1; # the number of lines to skip before pr +inting $len = $end - $start + 1; # the number of lines to print print / (?: # don't remember this () in $1..$n .*\n # all chars up to a newline and the \n ){$pre} # pre number of times ( # remember this (return it as first el of +list) (?: # but don't remember this part as 2nd elem +ent .*\n # match a line up to and including \n ){$len} # number-of-lines-to-print times ) # return as single (multi-line) value /mx' # /m: don't let '.' match \n (may not be n +ecessary)


    p