Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: multiple hash compare, find, create

by johngg (Canon)
on Dec 10, 2018 at 18:55 UTC ( [id://1227057]=note: print w/replies, xml ) Need Help??


in reply to multiple hash compare, find, create

I would choose the smallest of the three hashes and iterate over its keys in a loop doing an exists on the same key in the other two hashes, moving on to the next key unless existing in both of the others. If in all three, add an array ref to that key in the fourth hash. Something like:-

my %h4; foreach my $commonKey ( keys %h1 ) { next unless exists $h2{ $commonKey } && exists $h3{ $commonKey }; $h4{ $commonKey } = [ $h1{ $commonKey }, $h2{ $commonKey }, $h3{ $commonKey } ]; }

I hope this is helpful.

Cheers,

JohnGG

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-03-28 14:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found