Ok, given what you are doing your choice of using a hash is fair enough. The precision of the floating point values is fairly unimportant so any rounding or truncation that happens when using the numbers as keys is very unlikely to matter. To select the top N URLs I'd do something like:
use strict;
use warnings;
my %urls = (
0.999 => 'www.perlmonks.org',
0.65 => 'www.snakewranglers.org',
0.451 => 'www.jewelmerchants.org',
0.222 => 'www.coffeemerchants.org',
0.12 => 'www.scriptkiddies.org',
);
my @inOrder = sort {$b <=> $a} keys %urls;
my @topThree = splice @inOrder, 0, 3;
print "$_: $urls{$_}\n" for @topThree;
Prints:
0.999: www.perlmonks.org
0.65: www.snakewranglers.org
0.451: www.jewelmerchants.org
True laziness is hard work
|