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

Figured it out...to add the line that contains the match string, I added an additional line to the loop. Probably not the best way, but it works.

while (<$_>) { print OUT @history if /$pattern/; print OUT $_ if /$pattern/; # adds line with match push @history, $_; shift @history; }

Thanks again every one,

Neurotoxx

Replies are listed 'Best First'.
Re^6: How can I print three lines before pattern match?
by ikegami (Patriarch) on Aug 17, 2009 at 17:12 UTC

    Probably not the best way

    Indeed. You perform the regex match twice for nothing. The two previously submitted solutions are better. -- for asking for help then ignoring the answers twice.