Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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"; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: retrieving from a hash numerically
by Ido (Hermit) on Jul 04, 2005 at 13:20 UTC | |
by Anonymous Monk on Jul 04, 2005 at 13:31 UTC | |
|
Re: retrieving from a hash numerically
by polettix (Vicar) on Jul 04, 2005 at 13:24 UTC | |
|
Re: retrieving from a hash numerically
by rev_1318 (Chaplain) on Jul 04, 2005 at 13:34 UTC | |
|
Re: retrieving from a hash numerically
by dirac (Beadle) on Jul 04, 2005 at 13:27 UTC |