Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2023-12-11 21:44 GMT
Find Nodes?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?

    Results (41 votes). Check out past polls.