I have a 2D array. I can get a given column of it with the following:
my @column_zero=map {$_->[0]} @{$twod_array};
Then I can manipulate @column_zero at will.
But how do I place it back into the two dimensional array?
I have a 2D array. I can get a given column of it with the following:
my @column_zero=map {$_->[0]} @{$twod_array};
Then I can manipulate @column_zero at will.
But how do I place it back into the two dimensional array?
Perhaps it's better to get references to the values instead:
my @ref_to_column_zero = map { \($_->[0]) } @{$twod_array};
... so you can manipulate these values directly: you just need to remember that there are references stored in this array, so they should be dereferenced. For example:
for (@ref_to_column_zero) {
${ $_ } *=2;
}
If you prefer to use the old approach, you can do this:
for (0..$#column_zero) {
$twod_array->[$_][0] = $column_zero[$_];
}