in reply to Buffered read and matching
Read the file line for line and use a flag to indicate whether you want to collect lines or not, you could also call it a simple state machine:
my $errormatching=0; my @errortext=''; while (<>) { if (not $errormatching) { $errormatching=1 if m{^\s*'Errors' =>}; } else { if (not m{^\s*\]}) { push @errortext, $_; } else { process_error(@errortext); @errortext=(); $errormatching=0; } } }
UPDATE: Fixed typo where I used [ instead of ] in the regex
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Buffered read and matching
by Perlbotics (Archbishop) on Oct 15, 2008 at 12:35 UTC | |
by jethro (Monsignor) on Oct 15, 2008 at 13:41 UTC |