in reply to Re: Print Lines above and below string
in thread Print Lines above and below string

++ for "Close!" ...but "untested" lets typos slip by:

open (LOGFILE, "<$file") or die "Can't open $file"; my @lines = <LOGFILE>; my $lines; my $i; for $i(0..$#lines) { next unless $lines[$i] =~ /$string_to_find/i; my $a = $i - 5 < 0 ? 0 : $i - 5;; my $b = $i + 5 > $#lines ? $#lines : $i + 5; for $i($a..$b) { print $lines[$i]; } }