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
True laziness is hard work

Replies are listed 'Best First'.
Re^4: Hash table manipulation
by sarvan (Sexton) on Jul 13, 2011 at 04:23 UTC
    Hi GrandFather,

    Thanks for the post. But this sorting and getting the highest value, i have already done.

    I have asked for how could i get the values that are higher than certain threshold.. Plz let me know if my explanation is not adequate..

      Change the selection line to:

      my @topThree = grep ($_ > 0.4) @inOrder;

      replacing 0.4 with whatever your selection threshold value is.

      True laziness is hard work