in reply to Re: How can I print three lines before pattern match?
in thread How can I print three lines before pattern match?

That doesn't work if the pattern is found in the first three lines. (And what's with the quotes around a variable?) Change
print "$file[$_]" for ($i-3 .. $i-1);
to
print $file[$_] for grep $_ >= 0, $i-3 .. $i-1;

Replies are listed 'Best First'.
Re^3: How can I print three lines before pattern match?
by bichonfrise74 (Vicar) on Aug 14, 2009 at 04:39 UTC
    Thanks ikegami. Those are good points.