我有一个二维数组,我想把第一个元素放入一个简单的数组:
use strict; use warnings;
use Data::Dump;
my @matrix = ([1,2,3], [4], [5,6]);
my @array = (7,8,9);
my @list = $matrix[0];
print "matrix: " ; dd \@matrix;
print "array: " ; dd \@array;
print "list: " ; dd \@list;
print "size of matrix is ", scalar(@matrix), "\n";
print "size of array is ", scalar(@array), "\n";
print "size of list is ", scalar(@list), "\n";
如果我运行它,我会得到输出:
matrix: [[1, 2, 3], [4], [5, 6]]
array: [7, 8, 9]
list: [[1, 2, 3]]
size of matrix is 3
size of array is 3
size of list is 1
所以list
看起来还是一个二维数组,如何从矩阵的第一个元素得到一个类似array
的一维数组呢?
1条答案
按热度按时间nxowjjhe1#
您引用了一个数组。您需要取消引用它。更改:
至:
更改后,输出如下:
请参阅perldsc