The code will copy the contents of the list to the new list. However, if you store links in a list (and you need to create a two-dimensional array in Perl), the links are copied, not the objects that the links point to. Therefore, when you manipulate one of these objects with a link through one list, it seems that the other list changes when in fact both lists contain only the same links.
You will need to make a βdeep copyβ of the list if you also want to duplicate all the objects referenced. See this question for some ways to achieve this.
Given your case of a two-dimensional array, this should work:
@data_new = map { [@$_] } @data;
cdhowie
source share