The thing is, I want to set the array reference later and not when the 
object is being created.


>From: [EMAIL PROTECTED] (Randal L. Schwartz)
>To: "Nick Transier" <[EMAIL PROTECTED]>
>CC: [EMAIL PROTECTED]
>Subject: Re: Self Def
>Date: 19 Jun 2001 14:12:13 -0700
>
> >>>>> "Nick" == Nick Transier <[EMAIL PROTECTED]> writes:
>
>Nick> Given that I am trying to define an object attribute which is an 
>array
>Nick> of references to other object of the same type, how do I define this
>Nick> in the $self portion of my sub new constructor? This is what I have,
>Nick> will this work? Next is meant to hold an array of pointers or
>Nick> references.
>
>Nick> sub new {
>
>Nick>  my $invocant = shift;
>Nick>  my $class = ref($invocant) || $invocant;
>Nick>  my $self = {
>Nick>          Next,
>Nick>          @_,
>Nick>  };
>Nick>  return bless $self,$class;
>
>Nick> }
>
>You need an array ref there, not an array.  Simplest would be a
>shallow copy of the invocation list.
>
>     sub new {
>       my $class = shift; # do NOT use the ref() garbage, please
>       my $self = { Next => [@_] };
>       bless $self, $class;
>     }
>
>You might be able to get away with \@_ in place of [@_], but I know
>this is safer. :)
>
>See "perldoc perlboot" for more details.
>
>--
>Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
><[EMAIL PROTECTED]> <URL:http://www.stonehenge.com/merlyn/>
>Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
>See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl 
>training!

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com

Reply via email to