In article <371C5AB4...@gredos.cnb.uam.es> on Tue, 20 Apr 1999
12:45:09 +0200, Federico Abascal <faba...@gredos.cnb.uam.es> says...
> does anybody knows how to join two hashes, if possible? (The two hashes
> have some keys similar)
The hash-slice approach is efficient. The values of the shared keys
from the second hash overwrite those of the original hash.
@hash1{keys %hash2} = values %hash2;
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
l...@hpl.hp.com
>Hello,
>does anybody knows how to join two hashes, if possible? (The two hashes
>have some keys similar)
>Thanks,
>Federico
If you mean merge them - i.e., you have %a and %b, and you want to put them
in %c without worrying about whether there are duplicate keys, try
%c = (%a, %b);
Otherwise, if you want to retain the duplicates, try Tie::AppendHash.
--- Joe M.
In comp.lang.perl.misc,
l...@hpl.hp.com (Larry Rosler) writes:
:The hash-slice approach is efficient. The values of the shared keys
:from the second hash overwrite those of the original hash.
:
: @hash1{keys %hash2} = values %hash2;
Not for huge hashes it isn't -- imagine a hash tied to a ten-million
element DBM file, for example. But for most cases, this is fine.
--tom
--
The steady state of disks is full.
--Ken Thompson