http://qs1969.pair.com?node_id=489

Hashes are lists of key value pairs
and merging %bar into %foo:
 @foo{keys %bar} = values %bar;
is pretty dang snazzy.

Replies are listed 'Best First'.
RE: Merging hashes
by Anonymous Monk on Dec 30, 1999 at 10:13 UTC
    how about just this: %foo = (%foo, %bar); the "(" cats the hashes in array context, making one long array with an even number of elements, then assigns that to a hash. Of course this is memory intensive for large hashes. So this is really not very good after all. I must meditate some more in silence...
RE: Merging hashes
by Anonymous Monk on Jan 02, 2000 at 20:34 UTC

    Perl is very wise. I have not tested, but I assume that in the case of %foo = (%foo, %bar); that the values of %bar that share keys with %foo will over write the value in the cat and the value in the new %foo will be from %bar?

    Sorry that sentence was so long, I got caught up in the moment. I use this, not only to garuntee %bar will over write %foo, but so anyone who looks at the code after me will have no dougts as to what I was attempting:

    foreach my $key (keys(%bar)){ $foo{$key} = $bar{$key}; }

    It is iterative, but shouldn't consume too much memory. This will even pass pointers kept in values. I'm afraid a cat would expand the array I was pointing to aswell. I have never tried though.

    -T

RE: Merging hashes
by root (Monk) on Oct 13, 1999 at 04:05 UTC
    I liked this meditation.
RE: Merging hashes
by Anonymous Monk on Apr 07, 2000 at 08:40 UTC
    Este es... the usual mesh.
Re: Merging hashes
by Anonymous Monk on Oct 05, 2013 at 16:30 UTC
    What about something deeper? A deeper meditation? For example a hash containing hashes where the second hash, %bar, takes presidence
      What about it?