Chris et all,

Thanks for the solutions, and for the heads up on the
novice mistake addressing array elements. Time to
start checking back through my scripts for that one.

Many thanks,

Richard

 --- Chris Nandor <[EMAIL PROTECTED]> wrote: > At 16:10
+0000 2001.11.09, Richard Smith wrote:
> >This seems such an obvious operation, but the
> syntax
> >escapes me. I have an array of up to 6 values,
> which I
> >want to add together. I am sure there must be a
> >shorthand version of this:
> >
> >$result = @array[0] + @array[1] + @array[2] +
> >@array[3] + ...etc
> 
> In perl 5.005 and above:
> 
>       $result += $_ for @array;
> 
> In perl 5.004 and previous (including MacPerl
> 5.2.0r4):
> 
>       for (@array) {
>               $result += $_;
>       }
> 
> Note that your @array[0] syntax is not proper; it
> should be $array[0].
> 
> -- 
> Chris Nandor                      [EMAIL PROTECTED]   
> http://pudge.net/
> Open Source Development Network    [EMAIL PROTECTED]   
>  http://osdn.com/ 

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page from News and Sport to Email and Music 
Charts
http://uk.my.yahoo.com

Reply via email to