9.9 A Horse of a Different Color


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 


Learning Perl Objects, References & Modules
Learning Perl Objects, References, and Modules
ISBN: 0596004788
EAN: 2147483647
Year: 2003
Pages: 199

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net