in reply to push to an array lines matching a pattern, and the lines before and after the matching
Re your desire to capture a match-line and two lines around it, pseudocode:
Open ( $filehandle "<" "path/to/filename.txt" ) or die, "Can't open $f +ile, $!; Read a $line; $buffer = $line; if ($line =~ /pattern/ { push @array, $buffer; push array $line; # the matching line read another $line; push it too; #and now, except for a match on the first line of a +file, or the last, we have 3 lines captured } else { do it all again... }
|
|---|