我是 Perl 新手,想将两个数组相乘:
my @array1 = (1,2,3);
my @array2 = (2,4,6);
并打印出来:
# output ==
# 2 4 6
# 4 8 12
# 6 12 18
编辑:
知道了
my @array1 = (1,2,3);
my @array2 = (2,4,6);
multiply_array(\@array1, \@array2);
sub multiply_array{
my ($a1, $a2)=@_;
for(my $i=0; $i<3; $i++){
for(my $j=0; $j<3; $j++){
my $x = @$a1[$i]*@$a2[$j];
print $x."\t";
}
print "\n";
}
}