如果我想使用循环向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' },'seq' => 'TTG','end' => '53','start' => '28' } ],#... );
解决方法
@H_404_18@ 如果你有一个哈希数组的哈希值,并想要添加一个新的哈希值每个数组的结尾,你可以这样做:
push @{ $_ },\%new_hash for (values %mother_hash);
此循环遍历%mother_hash的值(在本例中为数组引用)并为每次迭代设置$_.然后在每次迭代中,我们将对新哈希值new_hash的引用推送到该数组的末尾.