in reply to Re^2: Hash table manipulation
in thread Hash table manipulation
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Hash table manipulation
by sarvan (Sexton) on Jul 13, 2011 at 04:23 UTC | |
by GrandFather (Saint) on Jul 13, 2011 at 06:49 UTC |