如何从散列哈希中提取密钥名称? [英] How to extract key name from a hash of hash?
问题描述
%HoH =(
flintstones => {
丈夫=>fred,
pal =>barney,
},
jetsons => {
丈夫=>george,
$ wife =>jane,
his boy =>elroy,
},
simpsons => {
husband =>homer,
wife =>marge,
kid =>bart,
},
);
如何迭代每个内部哈希(比如flintstones),并提取关键字名称(丈夫,朋友)和相应的每个这样的迭代vales?
为我的$ k(键%{$ HoH {flintstones}}){
my $ v = $ HoH {flintstones} {$ k};
printkey is $ k; value is $ v \\\
;
}
另一种方法是使用 I have following hash of hash : ); How to iterate over each inner hash (say flintstones) and also extract the key names (husband, pal) and corresponding vales for each such iteration? another way would be using
这篇关于如何从散列哈希中提取密钥名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! each $ c $($ k,$ v)= each%{$ HoH {flintstones}}){。$ c $ <$ p
pre $ ..}
%HoH = (
flintstones => {
husband => "fred",
pal => "barney",
},
jetsons => {
husband => "george",
wife => "jane",
his boy => "elroy",
},
simpsons => {
husband => "homer",
wife => "marge",
kid => "bart",
},
for my $k (keys %{ $HoH{flintstones} }) {
my $v = $HoH{flintstones}{$k};
print "key is $k; value is $v\n";
}
each
while( my($k, $v) = each %{ $HoH{flintstones} }) { ... }