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

What does the '' vs. "\n" do?

How could I print also the same line that has the pattern match?

Thank you Sifu,<\p>

Neurotoxx

  • Comment on Re^4: How can I print three lines before pattern match?

Replies are listed 'Best First'.
Re^5: How can I print three lines before pattern match?
by ikegami (Patriarch) on Aug 15, 2009 at 02:12 UTC
    Print the empty string prints nothing. Printing a newline prints an empty line.
    my @history = ('') x 3; while (<>) { print @history, $_ if /pattern/; push @history, $_; shift @history; }
    or
    my @history = ('') x 4; while (<>) { push @history, $_; shift @history; print @history, $_ if /pattern/; }