[Wellington-pm] Sum in one line

Finlay Thompson finlay at catalyst.net.nz
Mon Feb 28 19:07:14 PST 2005


Hi Everyone

I frequently want the sum of an array of numbers, and cant believe that 
perl has no "sum" function. Probably its coming in perl 6.

Anyway, does anyone know of a good oneliner ? The best I can do is:

   my $total = sub {my $s = 0; $s += $_ for @_; $s }->(@numbers);

Finlay


More information about the Wellington-pm mailing list