Section 12.9. A Horse of a Different Color


12.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 we 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 




Intermediate Perl
Intermediate Perl
ISBN: 0596102062
EAN: 2147483647
Year: N/A
Pages: 238

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