The blog post modified the original from returning an arrayref to returning a list.
Restoring the arrayref, I'd: use Algorithm::Loops 'MapCarE'; use List::Util 'sum'; sub pairwise_sum { [ MapCarE { sum @_ } @_ ] } (note that the only improvement offered by 5.19.9 would be to arbitrarily limit it to two arrays) On Tue, Feb 25, 2014 at 8:17 AM, Paul Makepeace <pa...@paulm.com> wrote: > On Feb 25, 2014 7:16 AM, "James Laver" <james.la...@gmail.com> wrote: >> >> >> On 25 Feb 2014, at 11:31, Matt Lawrence <matt.lawre...@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); >> } > > You aren't making a good case for perl here :) > >> >> James