You could just flatten out the loop you have:
my @foo = my @bar = qw(1 2 3 4); my @foobar; $foobar[$_] = $foo[$_] + $bar[$_] for 0 .. $#foo;
Now it will handle any two equally sized arrays and is fairly readable.
In reply to Re: Summing the elements of multiple arrays into a new array
by CharlesClarkson
in thread Summing the elements of multiple arrays into a new array
by djw
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |