sub add_vectors { my @left = @{ shift }; my @right = @{ shift }; my @result = (); my $index = $#left > $#right ? @left : @right; while( --$index >= $[ ) { $left[$index] = 0 if not defined $left[$index]; $right[$index] = 0 if not defined $right[$index]; $result[$index] = $left[$index] + $right[$index]; } return \@result; }