I have a hash with numerical values as keys and some data as values. I want to be able to retrieve the data in ascending numerical order based on the keys. My code seems to retrieve in a random order. The keys are all values from between 0 and 114. Can someone help?
my %hash = map {$nums[$_] => $sub_data[$_]} 0.. $#nums; my @gp_nums = (0..114); + + + + while ((my $key, my $value) = each %hash) { for (my $i=0; $i<@gp_nums; $i++) { if ($gp_nums[$i] == $key) { print "VALUE $value\n"; } } }
In reply to retrieving from a hash numerically by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |