in reply to adding to hashes

If you are dealing with simple hashes, such as the ones in your post, then the easiest way is as McDarren said.

If you are dealing with more complicated cases then you need to do a little more work, or use a module such as Hash::Merge to do the work for you.

For example, if you have the following hash:

my %a = ( k1 => 1, k2 => { kk3 => 3 }, ); my %b = ( k1 => 5, k2 => { kk4 => 4 }, ); my %c = (%a,%b);
In the above example a simple merge of the hashes results in the following:
%c = ( 'k1' => 5 'k2' => { 'kk4' => 4 }, );
Notice that the deep members of the hash are not merged, only the top level.

Replies are listed 'Best First'.
Re^2: adding to hashes
by imp (Priest) on Jul 24, 2006 at 17:50 UTC