In the following C # code:
int[] X = new int[2]; X[0] = 1; X[1] = 2; int[] Y = X; X[1] = 3;
After that, Y [1] will also be 3, since the operation Y = X does not make a clone, but rather assigns a link or pointer that X points to Y.
If the same operation is performed in Perl 5:
my @X = (1, 2); my @Y = @X; $X[1] = 3;
Unlike C #, Y [1] is not 3, but 2, which indicates that Perl makes a copy of the array after the operation @Y = @X.
So my question is: is there a way to assign or initialize a Perl 5 array with reference to another Perl array so that they both point to the same data? I already know about references and tried to dereference the array reference, but that also makes a copy. I also know that using an array reference will solve most of what I'm trying to do, so I don't need answers showing how to work with links.
source share