in reply to Problem Defining AoA from Named AoA

I must admit this is not very intuitive. Although the wrapper list @aoa1 and @aoa2 point to different locations in memory the internal array references do not. This can be shown by doing something like this: -
# these will be different # print \@aoa1."\n"; print \@aoa2."\n"; # but these won't be! # print $aoa1[0]."\n"; print $aoa2[0]."\n"; print $aoa1[1]."\n"; print $aoa2[1]."\n"; print $aoa1[2]."\n"; print $aoa2[2]."\n";
You can get around this by using a deep clone, i.e.
use strict; use warnings; use Storable qw(dclone); use Data::Dumper; # define @aoa1 w/ anonymous AoA # my @aoa1 = map { [qw(- - -)] } 0..2; # deep clone @aoa1 to create @aoa2 # my @aoa2 = @{dclone(\@aoa1)}; # modify @aoa2 # $aoa2[1][1] = '@'; # display structures # print Dumper(\@aoa1); print Dumper(\@aoa2);
Perhaps this information should be added to the Array Tutorial.