Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: hash map to give preference to 1st match

by DrHyde (Prior)
on Jun 28, 2011 at 10:04 UTC ( #911721=note: print w/replies, xml ) Need Help??


in reply to hash map to give preference to 1st match

You probably want to use a hash of arrayrefs:

my %results; while(my($score, $url) = getnextpair()) { push @{$results{$score}}, $url; }

Then to get the first URL that had a particular score ...

my $url = $results{$score}->[0]

and to get all the URLs that had a particular score ...

my @urls = @{$results{$score}}

And I'll echo what another monk said - please don't use $value or $val for the key in a hash, it's very confusing.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://911721]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (2)
As of 2023-12-10 07:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?











    Results (38 votes). Check out past polls.

    Notices?