Re: Array as instance variable
- From: Uri Guttman <uri@xxxxxxxxxxxxxxx>
- Date: Mon, 11 Dec 2006 12:23:42 -0500
"a" == anno4000 <anno4000@xxxxxxxxxxxxxxxxxxxxxx> writes:
a> 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).
a> That is an excellent solution if the array is the only data to be
a> kept in the object. If the array is just one field among others,
a> there is no other way than than to use an arrayref much like the OP
a> did.
and even if he uses a hash ref for the object and it has the array ref,
there is a very simple way to clean up the code of all those
$self->{array} expressions. just assign the array ref to a lexical in
the methods and use that. it is called factoring out common (or
constant) expressions and it is a very old coding and compiling
technique. you can think of it as useful case of a temp variable (just
don't ever name it 'temp'!).
uri
--
Uri Guttman ------ uri@xxxxxxxxxxxxxxx -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
.
- Follow-Ups:
- Re: Array as instance variable
- From: anno4000
- Re: Array as instance variable
- References:
- Array as instance variable
- From: robert.waters
- Array as instance variable
- From: robert.waters
- Re: Array as instance variable
- From: Uri Guttman
- Re: Array as instance variable
- From: anno4000
- Array as instance variable
- Prev by Date: Re: Removing entry from @rray
- Next by Date: Re: I can't print spanish characters on console
- Previous by thread: Re: Array as instance variable
- Next by thread: Re: Array as instance variable
- Index(es):
Relevant Pages
|