我有一个数组哈希(HoA)。我一直在使用$arrayrefs
. 但是,现在我需要检索$key
基于$arrayrefs
.
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。有人知道该怎么做吗?