in reply to DBI fetchall_arrayref

afaik the only real way to do this is to scan through matrix_ref and generate the array you want. SQL doesn't really allow you to do things like that.
# build a hash to mash all of the fruits together. # foreach my $row (@$matrix_ref) { # add the some_col to the fruit push(@{$tmp_hash->{$row[0]}}, $row[1]); } my $output; my $i; foreach my $fruit (keys(%$tmp_hash)) { # make the fruit the first element of the sub array push(@{$output->[$i]}, $fruit); # push the some_col's onto the array push(@{$output->[$i]}, @{$tmp_hash->{'fruit'}}; # start creating the next sub array $i++; } #output should now be what you want.
not tested, if it blows up your house it ain't my fault. :)

Replies are listed 'Best First'.
Re^2: DBI fetchall_arrayref
by kiat (Vicar) on Jun 15, 2004 at 15:45 UTC
    Thanks, amw1!

    I wasn't sure whether I could do it with SQL alone or perhaps with some version of DBI methods (like fetchall_hashref) that I'm not aware of. So now I know I can't do it with either SQL or DBI alone :)