Thanks for the info. I have been using perl on and off but
never tried its OO feature.
I followed the example in perlcod perlboot but got an error.
Here is my code
--------------------
Cow->speak;
{ package Animal;
sub speak {
my $class = shift;
print "a $class goes ",$class->sound,"!\n";
}
}
{ package Cow;
use vars qw(@ISA);
@ISA = qw(Animal);
print "Hi >$ISA[0]>\n";
sub sound {"Mooo"}
}
---------------------
After execution, I got
C:\Perl\MDGS>
C:\Perl\MDGS>
C:\Perl\MDGS>Sample.pl
Can't locate object method "speak" via package "Cow" at
C:\Perl\MDGS\Sample.pl line 2.
--------------------
Does this mean perl can't recgnize @ISA?
Thanks,
pac
Which Cow, which speak?
>
> { package Animal;
> sub speak {
> my $class = shift;
> print "a $class goes ",$class->sound,"!\n";
> }
> }
>
> { package Cow;
> use vars qw(@ISA);
> @ISA = qw(Animal);
> print "Hi >$ISA[0]>\n";
> sub sound {"Mooo"}
> }
> ---------------------
> After execution, I got
>
> C:\Perl\MDGS>
> C:\Perl\MDGS>
> C:\Perl\MDGS>Sample.pl
> Can't locate object method "speak" via package "Cow" at
> C:\Perl\MDGS\Sample.pl line 2.
>
> --------------------
>
> Does this mean perl can't recgnize @ISA?
>
> Thanks,
> pac
>
Move your speaking cow to the point beyond the package declarations and she
will no longer be silent.
Theo van den Heuvel
{package packat;
sub sound {"Duh!"}
}
I just follow the sample code in perldoc without reordering
the sequesce....
It works fine now. Hmmm.. I have a great projct for it.
Thnaks for you help,
pac
packar->
Duh!
> Theo van den Heuvel
packat> Cow-> speak;
packat> { package Animal;
packat> sub speak {
packat> my $class = shift;
packat> print "a $class goes ", $class->sound, "!\n";
packat> }
packat> }
packat> { package Cow;
packat> use vars qw(@ISA);
packat> @ISA = qw(Animal);
packat> print "Hi >$ISA[0]>\n";
packat> sub sound {"Mooo"}
packat> }
packat> After execution, I got
packat> Sample.pl Can't locate object method "speak" via package
packat> "Cow" at C:\Perl\MDGS\Sample.pl line 2.
packat> Does this mean perl can't recgnize @ISA?
It means you've put the "Cow->speak" too early, before Perl execute
the statements that assigns @Cow::ISA. Try putting it into the last
statement, and remember that Perl execute each file in your program
line by line (except that subroutines are defined before anything is
executed, together with the things you put in BEGIN {}, includes by
"use", etc).
Regards,
Isaac.