【发布时间】:2018-08-01 22:00:35
【问题描述】:
在 perl 中将两个数组(按列)合并为一个新的复合数组的方法是什么?
@array1
car
scooter
truck
@array2
four
two
six
我尝试使用以下方法:
my @merged = (@array1, @array2); print @merged;
但它将两个数组合并在一列中,如下所示:
car
scooter
truck
four
two
six
但我想要的是如下:
@merged[0] @merged[1]
car four
scooter two
truck six
【问题讨论】:
-
您想要一个 3x2 数组?
my @merged = ( \@array1, \@array2 );但是你需要使用 2 个索引来获取值。my $scooter = $merged[0]->[1]; -
多维数组应该可以
-
阅读
perldoc perldsc:perldoc.perl.org/perldsc.html#ARRAYS-OF-ARRAYS