in reply to Simple Array Followup

I guess you want something like:
my (@array, $keep); while (<$handle>) { if (!@array) {$keep = /FIRST_PATTERN/;} next unless $keep; # Next if we haven't seen the first pattern. push @array, $_; next unless $keep = !/SECOND_PATTERN/; # Next unless the second pattern is seen. process_array \@array; # Process and print print @array; @array = (); }
As for 'array manipulation', what kind of manipulation are you looking for? What is it what you want that splice doesn't do for you?
Perl --((8:>*

Replies are listed 'Best First'.
Re^2: Simple Array Followup
by jriggs420 (Sexton) on Oct 27, 2005 at 16:56 UTC
    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?

      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