Hi I have two arrays containing 4 columns and I want to subtract the value in column 1 of array2 from the value in column 1 of array1 and the value of column2 of array2 from column2 of array1 and so on. Example:
my @array1=(4.3,0.2,7,2.2,0.2,2.4)
my @array2=(2.2,0.6,5,2.1,1.3,3.2)
therefore the required output
2.1 -0.4 2 # [4.3-2.2] [0.2-0.6] [7-5]
0.1 -1.1 -0.8 # [2.2-2.1] [0.2-1.3] [2.4-3.2]
The code is used for this.
my @diff = map {$array1[$_] - $array2[$_]} (0..2);
print OUT join(' ', @diff), "\n";
and the result that I get now is
2.1 -0.4 2
2.2 -1.1 3.8
Again, the first line is used from the first, not the second row, how can I solve this problem?
I need to output rows of 3 columns as shown above, so I filled my array in a row of three values.
source
share