in reply to Re: Re: Beginner's Object Orientation Exercises?
in thread Beginner's Object Orientation Exercises?
I think that I could change
into something like:sub set_power { my $self=shift; my $power=shift; push @{$self->{POWERS}}, $power; } sub get_powers { my $self=shift; my $num=1; foreach my $power ( @{$self->{POWERS}} ) { print "$num => $power\n"; $num++; } print "\n"; }
It would be called as $obj->power("Power name") to set, and $obj->power() to view.sub power { my $self=shift; if ($_[0]) { my $power=shift; push @{$self->{POWERS}}, $power; } else { my $self=shift; my $num=1; foreach my $power ( @{$self->{POWERS}} ) { print "$num => $power\n"; $num++; } print "\n"; } }
> munchie, the number munchin newb
Llama: The other other white meat!
(you had to be there :-P)
|
---|
In Section
Seekers of Perl Wisdom