in reply to arrays of object in OO perl

Unfortunately, the biggest problem with using references seems to be getting the syntax right. Try thi:

sub getIndividual{ my $this = shift; my $index = shift; return $this->{individual}->[$index]->getDNA(); }

The problem with your version was you were trying to call a method on an array slice.

G. Wade

Replies are listed 'Best First'.
Re^2: arrays of object in OO perl
by IL_MARO (Initiate) on Nov 19, 2008 at 06:34 UTC
    I tried with the suggested code
         return $this->{individual}->[$index]->getDNA();
    but the output is always the same:   Can't call method "getDNA" on an indefined value at Population.pm ...
    I want to point out that I don't push into Population empty arrays.