
Jasmine
Administrator
Jan 19, 2001, 3:31 PM
Post #1 of 1
(4883 views)
|
How can I get the unique keys from two hashes?
|
Can't Post
|
|
(From the Perl FAQ) How can I get the unique keys from two hashes? First you extract the keys from the hashes into arrays, and then solve the uniquifying the array problem described above. For example: %seen = (); for $element (keys(%foo), keys(ēr)) { $seen{$element}++; } @uniq = keys %seen; Or more succinctly: @uniq = keys %{{%foo,ēr}}; Or if you really want to save space: %seen = (); while (defined ($key = each %foo)) { $seen{$key}++; } while (defined ($key = each ēr)) { $seen{$key}++; } @uniq = keys %seen;
|