$all_rows = [ [R1C1, R1C2, ..., R1Cn], [R2C1, R2C2, ..., R2Cn], ..., [RnC1, RnC2, ..., RnCn], ];
Doesn't DWIW! If I do this:Well, AFAIK, Perl is more DWIM rather than DWIW. You may W an A, but by using fetchall_arrayref, you really M AoA. If you really M an A and you only want a single column from each row, then you can use selectcol_arrayref instead.
...that is, I've got an AoA -- I just want ... an A!
Output with Data::Dumper:# Table: group # Columns: id, name # Values: 1, Admin # 2, User # 3, Public my $sql = 'select * from group'; my $r = $dbh->selectcol_arrayref($sql); # default to first column # or, if you want the the 'name' column my @r = @{$dbh->selectcol_arrayref($sql, {Columns=>[2]})}; # we want t +he 2nd column # if you know the column name you want in advanced: my $sql2 = 'select name from group'; my @group_names = @{$dbh->selectcol_arrayref($sql2)}; print Data::Dumper->Dump( [$r, \@r, \@group_names], [qw(id name group_names)], );
$id = [ '1', '2', '3', ]; $name = [ 'Admin', 'User', 'Public', ]; $group_names = [ 'Admin', 'User', 'Public', ];
Update: (09-07-2007) Fixed typo, corrected syntax to Data::Dumper->Dump() (was Data::Dumper(...)). I know I should just copy/paste instead of retyping. *sighs*
Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!
In reply to Re^3: Why a reference, not a hash/array?
by naikonta
in thread Why a reference, not a hash/array?
by Cody Pendant
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |