Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^2: Array storage issue

by LanX (Canon)
on Apr 06, 2014 at 21:52 UTC ( #1081341=note: print w/ replies, xml ) Need Help??


in reply to Re: Array storage issue
in thread Array storage issue

Even if he doesn't like lexicals, using package and our would facilitate reading his code.

I suppose he saw strict complaining about undeclared variables and took it literally. :(

like:

> perl use strict; $x=23; __END__ Global symbol "$x" requires explicit package name at - line 2.

Cheers Rolf

( addicted to the Perl Programming Language)


Comment on Re^2: Array storage issue
Download Code
Re^3: Array storage issue
by viored (Novice) on Apr 06, 2014 at 22:04 UTC
    My issue isn't strict, I don't know why everyone says that. I have a small sample program that works perfectly, but I'm trying to merge something like it into the main code I'm working on. I think my problem is in the hd::store=[]; statement. When I push things into another array, does it push the values or just a reference to the values? Can I make it push just the values?

      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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1081341]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (12)
As of 2014-09-17 19:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (98 votes), past polls