in reply to Re: Simple Array Followup
in thread Simple Array Followup

That works very well, but what if the first pattern I am using is the same as the second pattern. For eample, a leading number? Does that mkae sense?

Replies are listed 'Best First'.
Re^3: Simple Array Followup
by radiantmatrix (Parson) on Oct 28, 2005 at 14:59 UTC

    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).

    <-radiant.matrix->
    A collection of thoughts and links from the minds of geeks
    The Code that can be seen is not the true Code
    "In any sufficiently large group of people, most are idiots" - Kaa's Law