in reply to Result set into array
If you would like to fetch all of the rows and have them in a hash then you need to specify which column should be used, as in this example:
In this example the structure would be as follows:my $hoh = $dbh->selectall_hashref($sql, $index_column);
Keep in mind that as it is returning a hashref the order of the rows will not be preserved. To preserve the order you would use selectall_arrayref as follows:$hoh = { 1 => {id => 1, col2=>"abc", col3=>"def", col4=>"ghi"}, 2 => {id => 2, col2=>"lmn", col3=>"opq", col4=>"rst"}, }
In this example the structure would be as follows:my $aoa = $dbh->selectall_arrayrefref($sql);
If you would like to preserve both the order and the column names, then you can use the Slice option for selectall_arrayref as follows:$aoa = [ [1,"abc", "def", "ghi"], [2,"lmn", "opq", "rst"], ]
In this example the structure would be as follows:my $aoh = $dbh->selectall_arrayref($sql, {Slice => {}});
$aoh = [ {id => 1, col2=>"abc", col3=>"def", col4=>"ghi"}, {id => 2, col2=>"lmn", col3=>"opq", col4=>"rst"}, ]
|
|---|