Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Union of Two Hashes

by maverick (Curate)
on Apr 09, 2002 at 14:35 UTC ( #157735=note: print w/replies, xml ) Need Help??


in reply to Union of Two Hashes

The question is a bit confusing...you 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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2023-01-30 17:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?