sub signatures coming

James Laver james.laver at gmail.com
Tue Feb 25 14:59:22 GMT 2014


On 25 Feb 2014, at 11:31, Matt Lawrence <matt.lawrence at virgin.net> wrote:

> On 25/02/14 11:18, James Laver wrote:
>> 
>> But I probably already have List::MoreUtils imported (because Perl).
>> 
>> sub pairwise_sum ($a1, $a2) {
>>   zip @$a1, @$a2;
>> }
>> 
>> And lets ignore the fact that the perl version that was used in the article was buggy. If $arg2 is shorter than $arg1 it breaks. zip’s supposed defined behaviour is to stop when either list runs out of elements.
> 
> Whereas this one is buggy because it doesn't actually do what it says on the tin. Where's the summation?
> 
> Matt

Ah yes. I’d just woken up.

sub pairwise_sum($a2,$a2) {
  map {shift($_)+shift($_)} (zip @$a1, @$a2);
}

James


More information about the london.pm mailing list