Adding Two Arrays In A Subroutine in Perl

This article demonstrates the implementation of Adding two arrays in a subroutine



Implementation

@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;
}