如果我想为 mother_hash
中的所有数组添加一个新的哈希值使用循环,语法是什么?
我的哈希:
my %mother_hash = (
'daughter_hash1' => [
{
'e' => '-4.3',
'seq' => 'AGGCACC',
'end' => '97',
'start' => '81'
}
],
'daughter_hash2' => [
{
'e' => '-4.4',
'seq' => 'CAGT',
'end' => '17',
'start' => '6'
},
{
'e' => '-4.1',
'seq' => 'GTT',
'end' => '51',
'start' => '26'
},
{
'e' => '-4.1',
'seq' => 'TTG',
'end' => '53',
'start' => '28'
}
],
#...
);
最佳答案
如果您有散列数组的散列并且想要添加一个新的散列到
在每个数组的末尾,您可以执行以下操作:
push @{ $_ }, \%new_hash for (values %mother_hash);
此循环遍历
%mother_hash
的值(在这种情况下是数组引用)并设置 $_
对于每次迭代。然后在每次迭代中,我们将引用推送到新哈希 %new_hash
到该数组的末尾。
关于arrays - 如何将新哈希附加到哈希数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45771364/