[英]Combine scalar array references in perl
I have a datastructure like: 我有一个像这样的数据结构:
$hashRef->{"key1"}->{"key2"} = ['1','2','3']
This $hashRef
gets new values every iteration of the for loop. $hashRef
在for循环的每次迭代中获取新值。 I am trying to append all of these to produce an output like so: 我试图将所有这些附加到生成这样的输出:
$hashRef->{"key1"}->{"key2"} = ['loop1.out1','loop1.out2','loop1.out3','loop2.out1','loop2.out2','loop2.out3',...]
loop1.ou1 is symbolic for the first output from loop 1 and not intended to be printed. loop1.ou1是循环1的第一个输出的符号,不打算打印。
Is this possible? 这可能吗?
You may use push
to append new values to the array: 您可以使用
push
将新值附加到数组:
push( @{$hashRef->{"key1"}->{"key2"}}, 'loop1.out1','loop1.out2','loop1.out3');
$aData = [ 'loop2.out1','loop2.out2','loop2.out3' ];
push( @{$hashRef->{"key1"}->{"key2"}}, @$aData);
print join(",",@{$hashRef->{"key1"}->{"key2"}} ),"\n";
Hope this is what you want: 希望这是您想要的:
map {
push(@{$hashRef->{"key1"}->{"key2"}}, "loop$count.out".$_);
} @{$arr2};
$count is the loop number. $ count是循环号。 @{$arr1} is the incoming array.
@ {$ arr1}是传入数组。
Thanks, 谢谢,
Anoop Anoop
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.