bittis has asked for the wisdom of the Perl Monks concerning the following question:
Lets take the following example:
package Farm; use strict; use warnings; sub new { my $className = shift; my $self = { $farmName,"", "farmMamals",(), "farmBirds",() }; bless $self,$className; return $self; } sub addFarmBirds { my self =shift; my tempBirds=[] ; # right way of initialising an array ?? if (@_){ @tempBirds=@_}; #now for the part i dont understand $self->{farmBirds} = @tempBirds; return } }
Here my intention is to declare a hash of variables that belong to the specific object (forgive my poor terminology, still trying to get the gribs of it). From what i understand farmBirds is declared as an array (not a reference to one).
If i now call myFarm->addFarmBirds(@someFarmBirdsArray) will that array's items be placed inside the farmBirds array internal to the object "myFarm"? Or are the variables i declared in the class Farm stored as references?
will something like
my @birds = $self->{farmBirds};
successfully make a copy of the farmBirds array in the @birds array? It doesnt not appear to be the case, any ideas on how i can make that happen?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Help!!!! POOP is confusing me!
by moritz (Cardinal) on Jul 16, 2008 at 11:53 UTC | |
Re: Help!!!! POOP is confusing me!
by almut (Canon) on Jul 16, 2008 at 13:09 UTC | |
by bittis (Sexton) on Jul 16, 2008 at 13:47 UTC | |
by stvn (Monsignor) on Jul 16, 2008 at 15:49 UTC | |
Re: Help!!!! POOP is confusing me!
by jds17 (Pilgrim) on Jul 16, 2008 at 11:58 UTC | |
by amarquis (Curate) on Jul 16, 2008 at 13:17 UTC | |
by jds17 (Pilgrim) on Jul 16, 2008 at 15:03 UTC | |
Re: Help!!!! POOP is confusing me!
by pjotrik (Friar) on Jul 16, 2008 at 12:07 UTC | |
Re: Help!!!! POOP is confusing me!
by GrandFather (Saint) on Jul 16, 2008 at 21:31 UTC |