I think you're using the wrong data structure. Hashes cannot have duplicate keys, and floating point numbers are a bad match for hash keys, anyway. Like: "0.456234" and "0.4562340" is the same numerical value, yet it's a different string (and thus: hash key).
I'd rather use an array of (value, url) tuples (maybe as anonymous arrays... With 2 loops, you can
- determine the max value
- fetch all tuples with that value.
Actually, if you do it smarter (but more complex), you can do it in one loop.
my @pairs = ([0.456234, 'url 1'], [0.42323, 'url 2'], [0.456234, 'url
+3'], [0.456234, 'url 4']);
my $max;
my @url;
foreach(@pairs) {
if(!defined $max or $max < $_->[0]) {
$max = $_->[0];
@url = $_->[1];
} elsif($max == $_->[0]) { # caution: exact identity with floati
+ng point numbers is rare, so this might disappoint a little
push @url, $_->[1];
}
}
use Data::Dumper; print Dumper (\@url);
p.s. your original data is wrong, as it's the second value that is the highest. I modified that value in my test code.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.