mpolo has asked for the wisdom of the Perl Monks concerning the following question:
Now to get the number of countries represented within class1, I use scalar(keys(%class1)).
My question is how to get the number of countries represented in the whole company.
Here is my (correctly working) code:
foreach (keys(%class1),keys(%class2),keys(%class3)) { $tot{$_}=1; } $t=scalar(keys(%tot));
Is this the "right" way to do this? Is there another way? Also, is it possible to "merge" two hashes in an automatic way? (My hunch is "no" because Perl can't know what to do with overlapping keys, but I thought I'd ask...)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(Ovid - use a HoA to merge hashes) Re: Combining hashes
by Ovid (Cardinal) on May 11, 2001 at 21:54 UTC | |
by MeowChow (Vicar) on May 11, 2001 at 22:32 UTC | |
|
Re: Combining hashes
by MeowChow (Vicar) on May 11, 2001 at 21:27 UTC | |
|
Re: Combining hashes
by LD2 (Curate) on May 11, 2001 at 21:05 UTC | |
|
Re: Combining hashes
by Sifmole (Chaplain) on May 11, 2001 at 21:48 UTC | |
by MeowChow (Vicar) on May 11, 2001 at 22:08 UTC | |
by Sifmole (Chaplain) on May 14, 2001 at 04:05 UTC |