0
my %main_hash = ( 
    'hash1' => {
        'key1' => '1-111',
        'key2' => '1-222',
        'key3' => '1-333'
    },  
    'hash2' => {
        'key1' => '2-111',
        'key2' => '2-222',
        'key3' => '2-333'
    }   
);

如何将内部哈希(hash1)的键值(1-111,1-222,1-333)与以下列表的相应值进行比较:

$list=   thekey1is : 1-111
         thekey2is : 1-222
         thekey3is : 1-333;

并为每次比较的结果维护一个标志?

4

1 回答 1

-1

你可以做这样的事情

#get all the keys
my @keys = keys %{ $main_hash{hash1} };

#check for each key
for my $key (@keys) {

    if  ($main_hash{hash1}{$key} == $main_hash{hash2}{$key}){
        print "$main_hash{hash1}{$key} and $main_hash{hash2}{$key} Match \n",
    }
    else{
        print "$main_hash{hash1}{$key} and $main_hash{hash2}{$key} Do not match \n",
    }


}
于 2013-05-28T16:32:09.593 回答