I'm surprised none of the replies so far used the range operator. I think it's the right tool for the job. This code is tested and working on Linux:
my $chunk = 0; my @data; open my $infd, '<', 'foo' or die "open: $!"; while (<$infd>) { next unless (my $c = /^-+/ .. /^\*+$/); next if ($c == 1); $chunk++, next if ($c =~ /E0$/); $data[$chunk] .= $_; } close $infd; ## show results for (0..$chunk-1) { print "-- beginning of chunk $_ --\n", $data[$_], "-- end of chunk $_ --\n"; }
Don't forget to s|foo|c:/test/showtech215.txt|; and s|(\$!)|\$^E $1|;.
--
David Serrano
In reply to Re: Spliting a log file into chunks and saving it into an array
by Hue-Bond
in thread Spliting a log file into chunks and saving it into an array
by blackadder
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |