perlquestion
Rajiv
hash
union
merge
intersection
iterate
I want to find the union of two hashes. I tried the option of merging the two hashes, but found that relatively slower. Can anybody suggest me a good optimized code for getting the union of two hashes. The option that i am trying looks like this:
<CODE>
foreach $k (sort keys %hash1) {
if (exists($hash2{$k})) {
$matchWords++;
}
}
</CODE>
This snippet runs faster than merging. I don't understand how ??
<p><i>Originally posted as a Categorized Question. </i></p>