use 6; # require perl v6
use List::Util qw/reduce/;
@foobar = @{reduce{@$a ^+ @$b}\(@foo, @bar, @baz, @etc)};
reduce will almost certainly be a built-in in Perl 6, so you won't need to use List::Util.
That hideously lovely third line certainly would do the job in Perl 6 (well done!), but was it really necessary to be so cruel to the mere mortals who'll have to maintain that code???
kwoff is perfectly correct -- in Perl 6 you'll just need:
@foobar = @foo ^+ @bar ^+ @baz ^+ @etc;or possibly even:
@foobar = ^sum(@foo,@bar,@baz,@etc);BTW, all of the above code has been tested. ;-)
In reply to Re: Re: Summing the elements of multiple arrays into a new array
by TheDamian
in thread Summing the elements of multiple arrays into a new array
by djw
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |