[Perl] Error trabajando con classes

Luis Medrano Zaldivar aldus@todito.com
Thu, 13 Mar 2003 01:49:29 +0000


----=_vm_0011_W1909510687_22006_1047520169
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Lista,=0D
=0D
Genere un script en perl donde mando llamando clases pero me esta marcand=
o este error:=0D
=0D
=0D
Can't locate animals/Cat.pm in @INC (@INC contains: C:/Perl/lib C:/Perl/s=
ite/lib=0D
 .) at animals.pl line 2.=0D
BEGIN failed--compilation aborted at animals.pl line 2.=0D
=0D
=0D
Aqui anexo una copia de los clases y de los scripts para que me avisen qu=
e ondas. Por cierto los archivos *.pm los tengo en el mismo subdirectorio=
 donde tengo el script.pl les agradecere toda su ayuda lo antes posible.=0D=

=0D
Luis=0D
=0D


___________________________________________________
Todito Card, internet f=E1cil y sin compromisos.
Todito Ilimitado, internet r=E1pido, seguro y econ=F3mico.



----=_vm_0011_W1909510687_22006_1047520169
Content-Type: application/octet-stream;
        name="script.pl"
Content-Disposition: attachment;
        filename="script.pl"
Content-Transfer-Encoding: 7bit

use strict;
use Winefred::Cat;
use Winefred::Dog;

my $dog  = Winefred::Dog->new('Fido');
my $cat1 = Winefred::Cat->new('Fluffy');
my $cat2 = Winefred::Cat->new('Muffy');

$dog->register(12, 'Mutt');
$cat1->register(3, '1.4');
$cat2->register(5, '3.2');

$dog->set_sound('Bark!');
$cat1->set_sound('Meow');
$cat2->set_sound('Yowl!');
$dog->set_sound('Woof!');

for my $animal ( $dog, $cat1, $cat2 ) {
    print "My pet ", $animal->get_name, 
          " makes the sound ", $animal->get_sound, "\n";
}

for my $cat ( $cat1, $cat2 ) {
    print "My cat ", $cat->get_name, 
          " has a hairball this big: ", 
          $cat->get_hairball_size, "\n";
}

print "My dog ", $dog->get_name, " is a ", $dog->get_breed, "\n";

exit;



----=_vm_0011_W1909510687_22006_1047520169
Content-Type: application/octet-stream;
        name="Dog.pm"
Content-Disposition: attachment;
        filename="Dog.pm"
Content-Transfer-Encoding: 7bit

package Winefred::Dog;

#----------------------------------------------------------------------
# The Winefred::Dog class.  Inherits from Winefred::Animal
#
# Each dog object is a blessed hash with attributes of
# $self = { age   => $age,
#           breed => $breed }
#
# Joel Grow
# joelg@u.washington.edu
#----------------------------------------------------------------------

use Winefred::Animal;
@ISA = qw (Winefred::Animal);  # inherit from Animal.pm
use strict;

use constant AGE => '_age';
use constant BREED => '_breed';

#my $AGE   = '_age';
#my $BREED = '_breed';

sub register { 
    # takes two arguments, dog age, and breed. Store this info in the object 
    my ($self, $age, $breed) = @_;
    $self->{AGE}   = $age;
    $self->{BREED} = $breed;
}

sub get_breed { 
    # takes no arguments, returns the breed.
    my ($self) = @_;
    return $self->{BRED};
}

1;



----=_vm_0011_W1909510687_22006_1047520169
Content-Type: application/octet-stream;
        name="Cat.pm"
Content-Disposition: attachment;
        filename="Cat.pm"
Content-Transfer-Encoding: 7bit

package Winefred::Cat;

#----------------------------------------------------------------------
# The Winefred::Cat class. inherits from Winefred::Animal
#
# Each Cat object is a blessed hash with attributes of
# $self = { age      => $user,
#           hairball => $hairball }
#
# Joel Grow
# joelg@u.washington.edu
#----------------------------------------------------------------------

use Winefred::Animal;
@ISA = qw(Winefred::Animal);  # inherit from Animal.pm
use strict;

my $AGE      = '_age';
my $HAIRBALL = '_hairball';

sub register { 
    # takes two arguments, cat age, and hairball diameter size (in inches). 
    # Store this info in the object
    my ($self, $age, $hairball) = @_;
    $self->{$AGE}      = $age;
    $self->{$HAIRBALL} = $hairball;
}

sub get_hairball_size {
    # takes no arguments, returns the hairball diameter size 
    my ($self) = @_;
    return $self->{$HAIRBALL};
}

1;



----=_vm_0011_W1909510687_22006_1047520169
Content-Type: application/octet-stream;
        name="Animal.pm"
Content-Disposition: attachment;
        filename="Animal.pm"
Content-Transfer-Encoding: 7bit

package Winefred::Animal;

#----------------------------------------------------------------------
# The Winefred::Animal base class.
#
# Each animal object is a blessed hash with the following attributes
# $self = { name  => 'animal name',
#           sound => 'type of sound' }
#
# Joel Grow
# joelg@u.washington.edu
#----------------------------------------------------------------------

use strict;

my $NAME  = '_name';
my $SOUND = '_sound';

sub new {
    # constructor, takes one argument, the animal name 
    my $class = shift;

    my $self = {};
    bless $self, $class;

    $self->_init(@_);
    return $self;
}

sub _init {
    my ($self, $name) = @_;

    $self->{$NAME} = $name;
}

sub register {
    # an abstract method. Make sure that it has to be overridden by the 
    # child class. 

    die "You are supposed to override me!";
}

sub get_name {
    # takes no arguments; returns the name of the animal 
    my ($self) = @_;
    return $self->{$NAME};
}

sub set_sound { 
    # takes one argument, the sound that an animal makes 
    # (for example "Bark!"). It stores this sound in the object 
    my ($self, $sound) = @_;
    $self->{$SOUND} = $sound;
}

sub get_sound {
    # takes no arguments; returns the sound of the animal. 
    my ($self) = @_;
    return $self->{$SOUND};
}

1;



----=_vm_0011_W1909510687_22006_1047520169--