Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: arrays of object in OO perl

by IL_MARO (Initiate)
on Nov 19, 2008 at 06:47 UTC ( #724488=note: print w/ replies, xml ) Need Help??


in reply to Re: arrays of object in OO perl
in thread arrays of object in OO perl

Guys, may the allmighty Spaghetti Monster bless you all!
I used strict, as suggested; I corrected all the mistakes. And now it works.
I know, THOU SHALL USE STRICT... but I was lazy. Now I made another step toward enlightment. Thanks again.


EDIT: it's not working... I mean: if I use the first slot of the array, it works:
return $this->{individual}->[0]->getDNA();
But if I use another slot, it turns out that is undefined.
return $this->{individual}->[2]->getDNA(); This means that I don't have an array of 'individual', despite I pushed 5 of them into the array. Mmm...

sub init { my $i; foreach $i (0 .. 4) { my $this = shift; my $empl = Animal->new(); $empl->setDNA(4, 6, 8, 10); push (@{$this->{individual}}, $empl); print " ".$i."\n"; print $this->{individual}->[$i]->getDNA(); } }

In this way, the output is
0 4 6 8 10 1 Can't call method getDNA ...
And thus definitively I don't have and array of Animal, but individual is just a scalar. Damn.


Comment on Re^2: arrays of object in OO perl
Select or Download Code
Re^3: arrays of object in OO perl
by ChOas (Curate) on Nov 19, 2008 at 07:50 UTC
    You want to take the
    my $this = shift;
    Outside of the for-loop.

    GreetZ!,
      ChOas

    print "profeth still\n" if /bird|devil/;
      Ok, I admit I'm a dumb;
      I hope I'm just soooooo tired... :-P

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2014-04-21 05:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (490 votes), past polls