【发布时间】:2018-01-28 00:12:44
【问题描述】:
如果我想使用循环向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); -
谢谢,会的。
-
@HåkonHægland 如果您愿意,请将您的评论复制并粘贴到答案中。这是一个非常优雅的答案。
-
@ChristopherBottoms 谢谢,我将其添加为答案。
标签: arrays perl hash perl-data-structures