The following array is the result of a database query, and I would like to add a column in Perl:
<snip>
foreach my $array_ref ( @stash ) {
print "@$array_ref\n";
}
<snip>
Output result:
bash-3.2$ ./test.pl
2014 2 1
2015 2 1
2016 2 1
2017 1 0.5
bash-3.2$
I manage to add a row at the bottom. For instance via the following code:
my @stashSum = ['Sum', $sumNumDiv, $sumDiv];
push (@stash, @stashSum);
This results in the following:
bash-3.2$ ./test.pl
2014 2 1
2015 2 1
2016 2 1
2017 1 0.5
Sum 7 3.5
bash-3.2$
I am searching for the code to add the following as a column to the original array:
my $i=0;
foreach my $array_ref ( @stash ) {
$totalDiv[$i] = $array_ref->[2] * 15;
print "$totalDiv[$i] \n";
}
The expected result is the following:
bash-3.2$ ./test.pl
2014 2 1 15
2015 2 1 15
2016 2 1 15
2017 1 0.5 7.5
bash-3.2$
Is there a way to 'push' a column onto an array in a similar manner as rows? If not, how are columns added to an array in Perl?
foreach my $array_ref ( @stash ) { push @$array_ref, "new_column" }