hi there,

I have a hash map %result(). which has key,value pair. The key is $val(which has list of floating point values like 0.45458427 and value is $url which has list of urls

I use this hash map to print the url which the highest value in $val(i.e key).

my Question now is, when this $val has two or more values same i.e {value1:0.456234,val2:0.642323,val3:0.456234,val4:0.456234). what happens it prints the val4's url instead of val1's url. since val1,val3,val4 has the same score, I want it to go in order 1,2,3 like that. But it directly prints 4th.

What can be the suggestion..??
my %results = (); foreach my $result (@file_content) { my $tit = $1 if ($result =~ /<title>(.+?)<\/title>/i); next unless $tit; # skip, if tit is not available #print "\n$tit\n"; my $url = $1 if ($result =~ /<url>(.+?)<\/url>/i); my $val = jaccard($tit, $title); #print " $val\n"; $results{$val} = $url; } @results = sort {$b <=> $a} keys %results;#sorts in descending order. my $highest_val = $results[0];#takes the highest value print $highest_val; print "\n\n The Url Ur looking for is: $results{$highest_val}\n#print +s the url of highest values.
My code is this. i cant include the content of @file_content,because it very big. it has title,url,snippet for googles top 10 result. And "jaccard($tit,$title) is a funtion returns floating point value. since its also big i dint include. lets say $val has the following floating point values: 1-> 0.0588235294117647 2-> 0.0555555555555556 3-> 0.0588235294117647 4-> 0.0588235294117647 5-> 0 6-> 0.0555555555555556 7-> 0.0588235294117647 8-> 0.0555555555555556 here i expect the url of 2nd but getting url of 6th..

In reply to hash map to give preference to 1st match by sarvan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.