http://qs321.pair.com?node_id=153180


in reply to Re: Re: Beginner's Object Orientation Exercises?
in thread Beginner's Object Orientation Exercises?

I think that I could change
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"; }
into something like:
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"; } }
It would be called as $obj->power("Power name") to set, and $obj->power() to view.

> munchie, the number munchin newb
Llama: The other other white meat!
(you had to be there :-P)