home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Learning Perl Objects, References & ModulesLearning Perl Objects, References & ModulesSearch this book

9.9. A Horse of a Different Color

Having all horses be brown would be boring. Let's add a method or two to get and set the color:

## in Animal
sub color {
  my $self = shift;
  $self->{Color};
}
sub set_color {
  my $self = shift;
  $self->{Color} = shift;
}

Now you can fix that color for Mr. Ed:

my $tv_horse = Horse->named("Mr. Ed");
$tv_horse->set_color("black-and-white");
print $tv_horse->name, " is colored ", $tv_horse->color, "\n";

which results in:

Mr. Ed is colored black-and-white


Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.