chen li wrote:
>
> I have an array of array look like this:
>
> @array_of_array=(
>
>             [1,2,3,4,5],
>             [1,2,3,4,5],
>             [1,2,3,4,5],
>             [1,2,3,4,5]
> )
>
> How do I get the total values for each colume, such as
>
> $column1=1+1+1+1;
> $column2=2+2+2+2;
> $column3=3+3+3+3;
>
> ...

use strict;
use warnings;

sub sum { my $sum; $sum += shift while @_; $sum }

my @array_of_array = (
  [1,2,3,4,5],
  [1,2,3,4,5],
  [1,2,3,4,5],
  [1,2,3,4,5],
);

for (my $i = 0; exists $array_of_array[0][$i]; ++$i) {
  print sum(map $_->[$i], @array_of_array), "\n";
}


HTH,

Rob

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to