我有两个数组哈希。我想比较两个数组哈希中的键是否包含相同的值。
#!/usr/bin/perl
use warnings; use strict;
my %h1 = (
w => ['3','1','2'],
e => ['6','2','4'],
r => ['8', '1'],
);
my %h2 = (
w => ['1','2','3'],
e => ['4','2','6'],
r => ['4','1'],
);
foreach ( sort {$a <=> $b} (keys %h2) ){
if (join(",", sort @{$h1{$_}})
eq join(",", sort @{$h1{$_}})) {
print join(",", sort @{$h1{$_}})."\n";
print join(",", sort @{$h2{$_}})."\n\n";
} else{
print "no match\n"
}
}
if ("1,8" eq "1,4"){
print "true\n";
} else{
print "false\n";
}
输出应该是:
2,4,6
2,4,6
1,2,3
1,2,3
no match
false
但由于某种原因我if-statement
的不工作。谢谢