in reply to Re^2: Simple Array Followup
in thread Simple Array Followup
If the patterns are the same, then you actually have a simpler case (though the more complicated one shouldn't break, and is more generalized):
my @array; while (<DATA>) { last if /^d/ } #discard until the first match while (<DATA>) { if ( @array and /^d/ ) { process_array( @array ); undef @array; next; } push @array, $_; }
Of course, depending on the size of your data set, you could slurp and split:
my $data = join('',<DATA>); my @chunk = split(/^\d/m, $data); foreach (@chunk) { process_array( split(/\n/s, $_) ) }
But this latter assumes your data starts and ends OK (won't skip headers or the like).
|
|---|