Adding two arrays in a subroutine
@a = (1, 2, 3);
@b = (4, 5, 6);
@array = addem (\@a, \@b);
print @array;
sub addem
{
my ($ref1, $ref2) = @_;
while (@{$ref1}) {
unshift @result, pop(@{$ref1}) + pop(@{$ref2});
}
return @result;
}
Related examples in the same category