#!/usr/local/bin/perl my $VERSION = "1.02"; my $AUTHOR = "Prilusky"; my $YEAR = "2007"; package Animal; sub new { my $class = shift; my $object = {}; bless $object, $class; return $object; } sub isa { my $class = shift; return ref $class;} sub name { my $self = shift; my $name = shift; $self->{name} = $name if ($name); $self->{name} || "Unnamed"; } sub color { my $self = shift; my $color = shift; $self->{color} = $color if ($color); $self->{color}; } sub speak { my $self = shift; print $self->name, " goes ", $self->sound, "\n"; } sub eat { my $self = shift; my $food = shift; print $self->name, " eats $food.\n"; } package Horse; @ISA = qw(Animal); sub sound { "neigh" }; package Sheep; @ISA = qw(Animal); sub sound { "baaaah" }; # let's test it my $horse = Horse->new(); $horse->name("Mr. Ed"); $horse->eat("hay"); Sheep->eat("grass"); $horse->speak(); $horse->color('Black and White'); use Data::Dumper; print Dumper($horse);