in reply to DBI & processing groups of rows

Nothing wrong with your method, just need to add an extra process call after your while.

process(\@group) if @group;

Also, be sure to add error checking to your dbh executes

$sth->execute() or die $dbh->errstr;

Replies are listed 'Best First'.
Re^2: DBI & processing groups of rows
by Anonymous Monk on Apr 10, 2011 at 07:42 UTC
    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)

      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)