Don't ask to ask, just ask | |
PerlMonks |
Re^4: Array storage issueby GrandFather (Saint) |
on Apr 06, 2014 at 22:46 UTC ( [id://1081354]=note: print w/replies, xml ) | Need Help?? |
Perl arrays store scalar values. Scalar values are things like numbers, strings and references. When you copy an array (which includes push, pop and so on) you copy the scalar values of the elements. In a sense Perl doesn't do multiply dimensioned arrays. Instead it allows you to have an array of references to other (lets call them 'owned') arrays. When you copy an array of arrays you only copy the references so you end up with two arrays containing references to the same collection 'owned' arrays. You need to provide a way to make a deep copy of the data. Data::Deep may help (I've not used it). It may also be worth looking at PDL which is designed for data manipulation in Perl. BTW, I strongly endorse the other comments relating to using 'my' and package variables. Most likely if stuff broke when you used 'my' strict was highlighting either a bug or a design problem in your code.
Perl is the programming world's equivalent of English
In Section
Seekers of Perl Wisdom
|
|