chen li wrote:
> Dear all,

Hello,

> 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;

$ perl -le'
my @array_of_array = (
    [ 1, 2, 3, 4, 5 ],
    [ 1, 2, 3, 4, 5 ],
    [ 1, 2, 3, 4, 5 ],
    [ 1, 2, 3, 4, 5 ],
    );
my @total;
for my $row ( @array_of_array ) {
    for my $column ( 0 .. $#$row ) {
        $total[ $column ] += $row->[ $column ];
        }
    }
print "@total";
'
4 8 12 16 20



John
-- 
use Perl;
program
fulfillment

-- 
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