wcpyro has asked for the wisdom of the Perl Monks concerning the following question:
The following is the code for the class..use strict; require DoStuff; my $pop; my $hl; my $dogs = DoStuff->new(); #print 'Population to set?'; #$pop = <STDIN>; $dogs->pop(5); print $dogs->pop;
Health will be implemented just as soon as I can get the most basic variable defined in the object. From what I have read, the object itself should be automagically passed as the first variable when calling a class method. However, when the subroutine pop is executed, it seems no argument is passed. Any help on why this isn't working would be very much appreciated. If it matters, it's for a programming class, and so it does need to be implemented as an OO program.package DoStuff; use strict; ########################## sub new{ my $self = {}; $self->{pop} = undef; #$self->{health} = undef; bless($self); return $self; } sub pop{ my $self = shift; my $self->pop = shift; return $self->pop; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Object Awareness
by Joost (Canon) on Mar 10, 2008 at 00:47 UTC | |
by Anonymous Monk on Mar 10, 2008 at 01:20 UTC | |
by wcpyro (Novice) on Mar 10, 2008 at 05:54 UTC | |
by GrandFather (Saint) on Mar 10, 2008 at 10:38 UTC | |
by locked_user sundialsvc4 (Abbot) on Mar 10, 2008 at 14:05 UTC |