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
In reply to Re: Buffered read and matching
by jethro
in thread Buffered read and matching
by ropey
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |