[Omaha.pm] Some lines of a file

Robert Fulkerson robert.fulkerson at gmail.com
Sat Oct 25 17:50:45 PDT 2008


Y'know, I should be grabbing some of these ideas for quiz and exam
questions.  :)  That's certainly the oddball kind of thing one of us
goofball instructors would ask on an exam.  ;)
-- b

On Sat, Oct 25, 2008 at 7:37 AM, Jay Hannah <jay at jays.net> wrote:

> 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
>
>
> _______________________________________________
> Omaha-pm mailing list
> Omaha-pm at pm.org
> http://mail.pm.org/mailman/listinfo/omaha-pm
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/omaha-pm/attachments/20081025/83c72f38/attachment.html>


More information about the Omaha-pm mailing list