如何在perl中增加散列的散列
how to increment hash of hash in perl
未能使用此代码正确填充 HoH:
当我 运行 使用以下循环时:
while (my $form = $form_rs->next ()){
my $menu=$form->get_column("fmenu");
my $script=$form->get_column("fscript");
my $name=$form->get_column("ftitle");
$itemList->{$menu} = {
$script => $name
};
}
print Dumper $itemList;
它 运行 是正确的,但由于 $menu 重复它只保留 HoH 中的最后一个值。所以我在 Data Dumper 中得到错误的输出。每个 'menu' 我只得到 1 条记录,而应该有很多。
得到:
itemList=>{
menu1=>{
script1=>formName1
},
menu2=>{
script3=>formName3
}
...(and so on)
}
而预计:
itemList=>{
menu1=>{
script1=>formName1,
script2=>formName2
},
menu2=>{
script3=>formName3,
...(and so on)
}
...(and so on)
}
求助。
谢谢。
然后您想更新 $itemList->{$menu}{$script}
而不是将对单元素散列的引用分配给 $itemList->{$menu}
。
$itemList->{$menu}{$script} = $name;
未能使用此代码正确填充 HoH: 当我 运行 使用以下循环时:
while (my $form = $form_rs->next ()){
my $menu=$form->get_column("fmenu");
my $script=$form->get_column("fscript");
my $name=$form->get_column("ftitle");
$itemList->{$menu} = {
$script => $name
};
}
print Dumper $itemList;
它 运行 是正确的,但由于 $menu 重复它只保留 HoH 中的最后一个值。所以我在 Data Dumper 中得到错误的输出。每个 'menu' 我只得到 1 条记录,而应该有很多。
得到:
itemList=>{
menu1=>{
script1=>formName1
},
menu2=>{
script3=>formName3
}
...(and so on)
}
而预计:
itemList=>{
menu1=>{
script1=>formName1,
script2=>formName2
},
menu2=>{
script3=>formName3,
...(and so on)
}
...(and so on)
}
求助。 谢谢。
然后您想更新 $itemList->{$menu}{$script}
而不是将对单元素散列的引用分配给 $itemList->{$menu}
。
$itemList->{$menu}{$script} = $name;