我有一个数组哈希(HoA)。我一直在使用$arrayrefs
来处理这个HoA的值。但是,现在我需要根据$arrayrefs
检索$key
。Perl - 数组哈希:按值查找
my %a = (1 => "ONE" ,
2 => "TWO" ,
3 => " Three",);
my %aa = (4 => [ 'ONE' , 'TWO', 'THREE'],
5 => ['one' , 'two', 'three'],
6 => ['more', 'dos', 'some'],
);
my @array = ('ONE' , 'TWO', 'THREE');
my $array_ref = \@array;
# returns the $key where the $value is 'ONE'
my ($any_match) = grep { $a{$_} eq 'ONE' } keys %a;
print $any_match."\n"; # this returns '1', as expected.. Good!
my ($match) = grep { $aa{$_} eq @$array_ref } keys %aa;
print $match."\n"; # <--- error: says that match is uninitialized
在过去print
声明,我想它返回4.有没有人知道如何做到这一点?