⭐ in reply to How do I multiply the corresponding elements in two arrays together?
You could use List::MoreUtils:
use List::MoreUtils qw/pairwise/; @a = (1..5); @b = (6..10); @x = pairwise { $a * $b } @a, @b; print join ", ", @x; __END__ 6, 14, 24, 36, 50
Be sure to check both array have the same number of elements, or you could get a trail of zeroes:
use List::MoreUtils qw/pairwise/; @a = (1..5); @b = (6..8); @x = pairwise { $a * $b } @a, @b; print join ", ", @x; __END__ 6, 14, 24, 0, 0
|
|---|