in reply to Print 5 lines before and after pattern match from a list

You have two nested loops using $i as the looping variable. Just change the inner one to something else:

for my $j($a..$b){ print $write_tmp_app_log $lines[$j] };

UPDATE: added my to $j.

UPDATE: avoid the inner loop altogether:

print $write_tmp_app_log @lines[$a..$b];

UPDATE: I guess if you just had added a my to the $i in the inner loop like for my $i($a..$b){ it would work as well but for my personal feeling that would be to dangerous.

Replies are listed 'Best First'.
Re^2: Print 5 lines before and after pattern match from a list
by bitingduck (Deacon) on Mar 14, 2015 at 17:01 UTC

    The OP and your second update are reminders of why and how it's preferable to avoid C style loops in Perl. Perl's looping tools make C loops easy enough to avoid, and using C loops is an easy way to produce hard to notice but annoying bugs.