How can I sum arrays element-wise in Perl?
arrays, elementwise-operations, perl, sum
Solution
for Perl 5:
use List::MoreUtils 'pairwise';
@sum = pairwise { $a + $b } @arr1, @arr2;
Problem
I have two arrays: ``` @arr1 = ( 1, 0, 0, 0, 1 ); @arr2 = ( 1, 1, 0, 1, 1 ); ``` I want to sum items of both arrays to get new one like ``` ( 2, 1, 0, 1, 2 ); ``` Can I do it without looping through arrays?