On Wed, Jul 18, 2007 at 02:20:15PM +0900, Jack Minoshima wrote: > Hi. > Please allow me to ask another silly question. > > I wrote the program and it works fine. > > -------------------------------------------------------------------- > Animal.pm > package Animal; > use Exporter; > @ISA = qw(Exporter); > @EXPORT = qw(speak); > sub speak { > print "I speak!\n"; > } > 1; > > ---------------------------------------------------------------------- > Mouse.pm > package Mouse; > use Animal; > @ISA = qw(Animal); > @EXPORT = qw(speak sound); > sub sound { > print "the sound!\n"; > }; > 1; > > ------------------------------------------------------------------------ > farm.pl > use Mouse; > speak; > sound; > > C:\Documents and Settings\jackm\usetest>farm.pl > I speak! > the sound! > > but when I change Mouse.pm to replace "use Animal and set @ISA" with use > base, it won't work. > ---------------------------------------------------------------------- > Mouse.pm > package Mouse; > use base qw(Animal); > @EXPORT = qw(speak sound); > sub sound { > print "the sound!\n"; > }; > 1; > > C:\Documents and Settings\jackm\usetest>farm.pl > Can't call method "sound" on an undefined value at Animal.pm line 10. > > Please someone kindly let me know why?
Deriving from Exporter provides your package with an import() sub that will export the symbols you have specified (perldoc Exporter). "use" calls a module's import sub (perldoc -f use). "use base" doesn't (perldoc base). The purpose of "use base" is to establish a class hierarchy. OO doesn't really fit well with exporting. In the real world, you will probably need to pick a single paradigm and stick to it. -- Paul Johnson - [EMAIL PROTECTED] http://www.pjcj.net -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/