Perl Monk, Perl Meditation | |
PerlMonks |
Union of hashesby IvorW (Initiate) |
on Feb 07, 2002 at 10:58 UTC ( [id://143846]=perlquestion: print w/replies, xml ) | Need Help?? |
IvorW has asked for the wisdom of the Perl Monks concerning the following question:
Is there an easy way of getting the union of 2 hashes?
I know this can be done longhand with a loop, but I wondered if there was a better way.
foreach (keys %a) { $b{$_} = $a{$_}; } While this works, I wondered if there was a better way. I know the equivalent with arrays is easy. @b = (@b,@a); This might become significant for performance if one or other hash is not a real hash, but is tied to something. Any thoughts?
Back to
Seekers of Perl Wisdom
|
|