I would like to minimize the amount of code lines
Please read The path to mastery.
I don't quite understand what you want your resulting data structure to look like, and I don't know what you want to do with it, so I fear your need to provide more information. For example when you talk about a hash, what should be the keys, what should be the values? Which values do you expect in the arrays?
But one thing I know: if you do a query, and use the results only as input for another query, using just a single query with a join over both tables is probably more efficient and results in less Perl code. If you need the results in a particular order, a GROUP BY or ORDER BY clause can help.
| [reply] |
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!
| [reply] |
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;
}
| [reply] [d/l] |
That is not a Perl problem, but an SQL question.You want to join two tables. You will probably need something like: SELECT DISTINCT first_table.number, record_ids FROM first_table, secon
+d_table WHERE second_table.number = first_table_number;
Always let the database do as much work as possible: it will be more efficient and faster.
CountZero A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
| [reply] [d/l] |