in reply to DBI with hash of arrays



Sorry for the confusing explanation.
I was able to join the two queries and now I will have records that look similar like this but are currently stored in an array:

11 test
11 test2
22 break
22 break2
33 break3


Now I do not know my first column as there are more entries and I would like my hash of arrays to look like this:

%HoA = (
11 => "test", "test2" ,
22 => "break", "break2",
33 => "break3" ,
etc.
);
But I cannot even begin thinking of how I can accomplish this other than looping through the array and somehow exporting the first number and will need your help
Thank you!

Replies are listed 'Best First'.
Re^2: DBI with hash of arrays
by runrig (Abbot) on Mar 22, 2011 at 18:30 UTC
    my $sql = <<EOT SELECT col1, col2 FROM table.... EOT my $sth = $dbh->prepare($sql); $sth->execute(); $sth->bind_columns(\my ($col1, $col2)); my %data; while ($sth->fetch) { push @{$data{$col1}}, $col2; }