Shenanagians! I call Shenanagians! blakem broke the rules ;)
The original stipulations stated that the arguments would be supplied via command line; here is the shortest I came up with with that:
open(T,"$ARGV[0]"); foreach(@_=<T>){/$ARGV[1]/?print@_[$c..$ARGV[2+$c],exit:$c++} close(T)
Unfortunately, much space is taken up by the $ARGV. Also, note that by changing the exit to a "\n" (or removing it completely) will cause the code will print $ARGV[2] lines for ALL matches. Leaving the exit causes only the first batch to print.
Update:
I can cheat too (using blakem's arguments as an example):
and completely floor him; but, as I said, that would be cheating ;)perl -ne "print((<>)[0..3])if/ou/" test.txt
In reply to Re: Reading a pattern and a number of lines after it
by jryan
in thread Reading a pattern and a number of lines after it
by simon.proctor
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |