Perl : Hash of Hashes Refernced by Hash Key September 27 2004
Age old problem of traversing a hash of hashes based on a key from a different hash.
#!perl
use strict;
my(%HASH_1, %HASH_2);
$HASH_1{’URL1′} = 1;
$HASH_1{’URL2′} = 1;
$HASH_1{’URL3′} = 1;
$HASH_2{’URL1′}{’URL2′}=1;
$HASH_2{’URL1′}{’URL3′}=1;
$HASH_2{’URL2′}{’URL3′}=1;
$HASH_2{’URL3′}{’URL1′}=1;
while(my($key, $value) = each %HASH_1) {
if($HASH_2{$key}) {
my $hash_ref_copy = $HASH_2{$key};
while(my($key2, $val2) = each %$hash_ref_copy) {
print qq{ $key :: $key2 :: $val2 n};
}
}
}
Reference : Abatko
