sub signatures coming
Ruud H.G. van Tol
rvtol at isolution.nl
Tue Feb 25 11:58:38 GMT 2014
On 2014-02-25 04:45, Paul Makepeace 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)]
Some Perl alternatives:
sub pairwise_sum ($list1, $list2) {
[pairwise {$a + $b} @$list1, @$list2];
}
sub pairwise_sum (\@\@) {
pairwise {$a + $b} @{$_[0]}, @{$_[1]};
}
--
Ruud
More information about the london.pm
mailing list