Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: arrays of object in OO perl

by gwadej (Chaplain)
on Nov 19, 2008 at 04:58 UTC ( [id://724465]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-04-24 09:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found