Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Answer: Union of Two Hashes

( #157735=categorized answer: print w/ replies, xml ) Need Help??

Q&A > hashes > Union of Two Hashes contributed by maverick

The question is a bit ask for a union, but you code snippet looks like you're looking for the intersection. Union first. For small hashes this is really quick:
%union = (%first, %second);
For large:
while (($k,$v) = each %first) { $union{$k} = $v; } while (($k,$v) = each %second) { $union{$k} = $v; }
(makes sense once you consider the memory usage for the first snippet.

For intersection, all you really need to do is change $matchWords to $matchWords{$k}++ the iterate of then matchWords looking for values == 2

Comment on Answer: Union of Two Hashes
Select or Download Code
Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2015-11-26 19:47 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (706 votes), past polls