如何在Perl中生成一个矩阵(对引用数组的引用)X by Y?
答案 0 :(得分:2)
my $x = 5;
my $y = 3;
my $val = 23;
my @matrix = (
map [ ($val) x $x ], 1 .. $y
);
use Data::Dump;
dd @matrix;
输出:
(
[23, 23, 23, 23, 23],
[23, 23, 23, 23, 23],
[23, 23, 23, 23, 23],
)
答案 1 :(得分:0)
my @random = map [ map rand, 1..5 ], 1..10; # Generates a 5x10 matrix of random values