sub signatures coming
James Laver
james.laver at gmail.com
Tue Feb 25 11:18:14 GMT 2014
On 25 Feb 2014, at 03:45, Paul Makepeace <paulm at paulm.com> wrote:
> On Mon, Feb 24, 2014 at 2:04 PM, Steve Mynott <steve.mynott at gmail.com> wrote:
>> http://perltricks.com/article/72/2014/2/24/Perl-levels-up-with-native-subroutine-signatures
>
> Finally. But don't believe the python/perl comparison troll, as
> python, for once, actually outguns perl on a character chomping basis,
>
> sub pairwise_sum ($arg1, $arg2) {
> return map { $arg1->[$_] + $arg2->[$_] } 0 .. $#$arg1;
> }
>
> def pairwise_sum(list1, list2):
> return [i + j for i, j in zip(list1, list2)]
>
> Paul
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.
James
More information about the london.pm
mailing list