[Omaha.pm] Some lines of a file

Jay Hannah jay at jays.net
Sat Oct 25 05:37:05 PDT 2008


A friend of mine asked me for this one yesterday.


Problem:

   Given STDIN print everything except the first 2 lines and last 4  
lines.


Solution:

   while (<>) {
      push @in, $_;
   }
   print splice(@in, 2, @in - 6);


Note this is a terrible solution with large files (memory hog), but  
works fine on small STDIN.

Cheers,

j



$ cat j
one
two
three
four
five
six
seven
eight
nine
ten
$ cat j | perl j2.pl
three
four
five
six




More information about the Omaha-pm mailing list