Yes, I mentioned that in my writeup. But the fix is pretty straightforward, and is presented in the code below:
use strict; use warnings; my @buffer; my $re = qr/10/; while (<DATA>) { if ( $_ =~ $re ) { @buffer = (); my $count = 0; while( defined( my $discard = <DATA> ) and $count++ < 2 ){ if( $discard =~ $re ) { $count = 0; } } } else { push(@buffer, $_); if( @buffer > 5 ) { print shift(@buffer); } } } print @buffer; __DATA__ Line 01 Line 02 Line 03 Line 04 Line 05 Line 06 Line 07 Line 08 Line 09 Line 10 Line 11 Line 12 Line 13 Line 14 Line 15 Line 16 Line 17 Line 18 Line 19 Line 20
Dave
In reply to Re^3: Regex question
by davido
in thread Regex question
by jamsda
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |