Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

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
Replies are listed 'Best First'.
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.


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

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2015-11-28 09:29 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (740 votes), past polls