Dear all,
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;
...
Thanks,
-Original Message-
From: chen li [mailto:[EMAIL PROTECTED]
Sent: Friday, August 18, 2006 7:00 PM
To: beginners@perl.org
Subject: calculate the value in an array of array
Dear all,
I have an array of array look like this:
@array_of_array=(
[1,2,3,4,5
chen li schreef:
> 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
#!/usr/bin/perl
use warnings ;
use strict ;
m
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;
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;
>
On Fri, Aug 18, 2006 at 06:29:36AM -0700, chen li wrote:
> Dear all,
>
> 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 col
Dalibor Straka schreef:
> chen li:
>> @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
>
> it might be smart(depends on utilization) to keep the sum as the 0th
>
--- "John W. Krahn" <[EMAIL PROTECTED]> 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 c
chen li wrote:
: $total[ $column ] += $row->[ $column ];
:
: Can you or anyone else explain it a bit more?
It is short for this.
$total[ $column ] = $total[ $column ] + $row->[ $column ];
HTH,
Charles K. Clarkson
--
Mobile Homes Specialist
Free Market Advocate
Web Programmer
254 96