CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Frequently Asked Questions:
How can I get the unique keys from two hashes?

 



Jasmine
Administrator

Jan 19, 2001, 3:31 PM

Post #1 of 1 (2216 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:

Code
    %seen = (); 
for $element (keys(%foo), keys(ēr)) {
$seen{$element}++;
}
@uniq = keys %seen;

Or more succinctly:

Code
    @uniq = keys %{{%foo,ēr}};

Or if you really want to save space:

Code
    %seen = (); 
while (defined ($key = each %foo)) {
$seen{$key}++;
}
while (defined ($key = each ēr)) {
$seen{$key}++;
}
@uniq = keys %seen;


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives