[Wellington-pm] Sum in one line
Finlay Thompson
finlay at catalyst.net.nz
Mon Feb 28 19:15:24 PST 2005
thanks , thats much better!
Jacinta Richardson wrote:
>
> Finlay Thompson wrote:
>
>> Anyway, does anyone know of a good oneliner ? The best I can do is:
>>
>> my $total = sub {my $s = 0; $s += $_ for @_; $s }->(@numbers);
>
>
> $total += $_ for @numbers;
>
> of course if you're defining $total as well, it's a little harder.
> Perhaps:
>
> my $total; $total += $_ for @numbers;
>
> strictly speaking it's two lines, but it's shorter than your
> suggestion. ;)
>
> Good question!
>
> All the best,
>
>
> Jacinta
>
More information about the Wellington-pm
mailing list