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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.