| Next | February 2001 | Slide #14 |
$hamlet->set_name('Hamlet');
This is like Person::set_name($hamlet, 'Hamlet')
sub set_name {
my ($self, $new_name) = @_;
$self->{NAME} = $new_name;
}
Recall that $hamlet is an anonymous hash
Similarly set_age:
sub set_age {
my ($self, $age) = @_;
if ($age < 0) { croak "negative age" }
$self->{AGE} = $age;
}
Methods that exist only to set or get a data item are called Accessors
| Next | ![]() |
Copyright © 2001 M-J. Dominus |