我有一个看起来像这样的哈希表:
my $hash = {
level1_f1 => {
level2_f1 => 'something',
level2_f2 => 'another thing'
},
level1_f2 => {
level2_f3 => 'yet another thing',
level2_f4 => 'bla bla'
level2_f5 => ''
}
...
}
我还得到了一份与“level2”键对应的值列表,我想知道它们是否存在于哈希表中。
@list =(“level2_f2”,“level2_f4”,“level2_f99”)
我不知道@list中的每个元素属于哪个“level1”键。我能想到的唯一找到它们是否存在的方法是使用foreach循环遍历@list,另一个foreach循环遍历%hash的键并检查。foreach my $i (@array) {
foreach my $k (keys %hash) {
if (exists $hash{$k}{$list[$i]})
}
}
但我想知道是否有更有效或更优雅的方法来完成它。我发现的所有答案都要求您知道“level1”键,而我不知道。
谢谢!!