On Oct 27, radhika sambamurti said:
>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?
>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"});
>}
First, you don't want $results_hash to be my(). It'll lose its value each
time. Second, you want a hash. $foo = (1,2) ends up setting $foo to 2.
Third, doing %hash = (key, value) clears the entire hash each time. You
want to do:
my %results_hash;
while (my $res = ...) {
# two push()s
$results_hash{$res->{menu_item_number}} = $res->{description};
}
--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/
<stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
[ I'm looking for programming work. If you like my work, let me know. ]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]