需要在perl中创建2个数组的矩阵

时间:2015-10-08 12:15:37

标签: arrays perl

我有两个数组:

array_1: 1 2 3 4 5 6 
array_2: 0.1 0.2 0.3 0.4 0.5 0.6

两个数组的大小相同。现在我们需要以这种格式打印,

1  with 0.1
1  with 0.2
1  with 0.3
1 with  0.4
1  with 0.5

2  with  0.1
2  with  0.2
2  with  0.3
2  with  0.4
2  with    0.5
2 with    0.6



6  with   0.1
6  with  0.2
6  with  0.3
6  with  0.4
6  with  0.5
6  with  0.6

请帮我怎样在Perl中打印?

1 个答案:

答案 0 :(得分:3)

#!/usr/bin/perl
use strict;
use warnings;
my @array1 = qw(1 2 3 4 5 6 );
my @array2 = qw(0.1 0.2 0.3 0.4 0.5 0.6);
foreach my $item (@array1){
    foreach (@array2){
        print "$item with $_\n";
    }
    print "\n";
}

Demo