in reply to Re: Problem in Passing A Multidimensional Array into a Function
in thread Problem in Passing A Multidimensional Array into a Function

Here is an example of a deep copy, for reference. Note that this is not efficient - you'd be better off using a module as GrandFather suggests. (Modules are great for getting things done, but don't always show you how they are doing them.)

my @a1; # First array # Pretend we're putting something in the first array. my @a2=aoacpy(@a1); sub aoacpy { my @array_in=@_; my @array_out; # Iterate through parent array. for (my $i=0; $i<scalar(@array_in); $i++) { # Iterate through child array - note that # we do this for each member of the parent # array. for (my $j=0; $j<scalar($array_in[$i]); $j++) { $array_out[$i][$j]=$array_in[$i][$j]; } } return @array_out; }

I'm now scratching my head trying to work out why this is so slow - it shouldn't be iterating that many times.