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/