On Fri, Nov 09, 2001 at 04:10:31PM +0000, 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 > > Any help would be much appreciated.
How about: $result = 0; $result += $_ for @array; BTW, when you're accessing a single element from an array, you should really write $array[0] rather than @array[0]. -w will give you a warning for the latter. Ronald