Re: Array as instance variable



Uri Guttman <uri@xxxxxxxxxxxxxxx> wrote in comp.lang.perl.misc:
"rw" == robert waters <robert.waters@xxxxxxxxx> writes:

rw> Also, how would I go about populating that array inside the
rw> constructor?

this is in response to BOTH of your postings. please even quote yourself
if you have to do this.

you can use ANY reference for an object, not just hashes. hashes just
are the most common and usually direct way to do perl objects. get the
book Object Oriented Perl by damian conway and learn how to make objects
out of any ref including arrays. that will also show you how to
initialize them (hint: just the same as with any array you need to
init).

That is an excellent solution if the array is the only data to be
kept in the object. If the array is just one field among others,
there is no other way than than to use an arrayref much like the OP
did.

Anno
.



Relevant Pages

  • Re: Counting keys in an array of hashes?
    ... I would like to sort the array based on the value of $data ... I am not proficient with hashes, so I apologize in advance for my ... This is a hash slice*. ...
    (perl.beginners)
  • Re: Question about multi-demension hash initialization
    ... On Sat, Sep 20, 2008 at 10:47 AM, Robert Klemme ... You know how to create nine hashes but you do not know how to ... For example, I have a multidimensional array, which I then take each ...
    (comp.lang.ruby)
  • Re: Parsing an Array of Hashes
    ... I am dealing with an array of hashes in my program. ... I need to either retain this hash or delete this hash from the array. ... I need to parse arrayOfAll, picking up each Hash turn by turn, and in ...
    (comp.lang.perl.misc)
  • Re: excessively verbose request for help with regex and arrays
    ... The part where you describe Arrays of Hashes is a bit confusing as well, can you describe your data structure using code rather than English? ... This doesn't check for multi-line strings, names with ':' in and other weirdness though. ... If you have an Array of text lines then you can just iterate through, scan each one and store the data in another Array: ...
    (comp.lang.ruby)
  • YAHP - Ref to a hash via xml::simple prob.
    ... I am trying to get to grips with a fragment of an XMLin structure ... Set=Array of Hashes ... and can work out what I want, but the array Ummmm. ... Dumping $m->shows ...
    (comp.lang.perl.misc)