++ 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]; } }
In reply to Re^2: Print Lines above and below string
by ww
in thread Print Lines above and below string
by coding_new
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |