Hi, As per the code below, I am trying to read from the database and put the values into a hash list, so that I can retrieve the values later. I have managed to put the values into arrays, but am not able to put them into a hash. Any ideas how this can be done/improved?
### code below######
while (my $res = $sth->fetchrow_hashref()) { push(@menu_id, $res->{"menu_item_number"}); push(@menu_desc, $res->{"description"}); my $results_hash = ($res->{"menu_item_number"}, $res->{"description"}); }
Not too bad. Though, by 'retrieve the values later' I assume you mean after the while loop, yes? If so, it would be a good idea to change the scope of the hash to reflect that...
Try:
my $results_hash; while (my $res = $sth->fetchrow_hashref()) { push(@menu_id, $res->{"menu_item_number"}); push(@menu_desc, $res->{"description"}); $results_hash = ($res->{"menu_item_number"}, $res->{"description"}); }
Then the hash won't expire at the end of the loop.
Daniel T. Staal
--------------------------------------------------------------- This email copyright the author. Unless otherwise noted, you are expressly allowed to retransmit, quote, or otherwise use the contents for non-commercial purposes. This copyright will expire 5 years after the author's death, or in 30 years, whichever is longer, unless such a period is in excess of local copyright law. ---------------------------------------------------------------
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]