in reply to working with multiple hash refs
This will get you part of the way there...
As for knowing which hash the key came from, that's a bit more difficult and your request is actually ambiguous. What do you want to do about keys which are in both hashes?for my $key (sort keys %{$hash{A}{B}{C}{D}}, keys %{$hash{A}{B}{C}{E}) + { print $key,"\n"; }
You will probably need to extract the keys into another data structure. You could, for instance, use an array of array references where each reference refers to an array of two elements. The first would be the key and the second would be either 'D' or 'E'.
Something like this (untested) code:
my @allkeys; push @allkeys, [$_, 'D'] for keys %{$hash{A}{B}{C}{D}}; push @allkeys, [$_, 'E'] for keys %{$hash{A}{B}{C}{E}}; for my $ref (sort {$a->[0] cmp $b->[0]} @allkeys) { my $key = $ref->[0]; my $which = $ref->[1]; print "$key from $which hash.\n"; }
Edit: Changed $key to $_ on the "push ... for" lines. ++tachyon for spotting the error.
-sauoq "My two cents aren't worth a dime.";
|
|---|