http://www.perlmonks.org?node_id=99416


in reply to creating 2D arrays

As has already been explained by others, a reference must be used in place of an array itself.

I'd like to add just one thing. For performance reasons, i'd rather change the sub mult to return the array reference rather than the array itself. Also, pass an array reference as the second param to mult instead of an array.

sub mult { my ($a, $b) = @_; # dereference the array, process it and create a new array .... return \@c; } ## Assuming that the array @b is a 2D array too for $i (0..$N){ push @results, mult($a, $b[$i]); }