in reply to Re: DBI & processing groups of rows
in thread DBI & processing groups of rows

I was really hoping to avoid the "extra" call to process(), as it reeks of code duplication (especially if there are more arguments than just \@group)

Replies are listed 'Best First'.
Re^3: DBI & processing groups of rows
by wind (Priest) on Apr 11, 2011 at 05:02 UTC

    Well, if you don't care about memory consumption, you can always create all the groups first

    my @group; while (my $row = $sth->fetchrow_hashref) { push @group, [] if !@group || $row->{foo_id} == $group[-1][0]{foo_id}; push @{$group[-1]}, $row; } process($_) for (@group);
      Thank you for your input. I ended going with the format I wrote in the original post (although with the else block removed to reduce indentation)