我有一个看起来像这样的哈希:
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”键,而我不知道。
谢谢!!