The following code is all in a single file. The problem is that ISA is not behaving as expected.
QUESTION1: why is the error message being generated? I need package B to "inherit" the SayBye subroutine from A.
QUESTION2: How does this code need to change when Packages A and B are moved to their own separate files?
QUESTION3: What else is wrong with this code if anything?
A search did not reveal any straightforward simple barebones example ... that's all that is needed.
use strict; package A; require Exporter; our @ISA = qw/ Exporter /; our @EXPORT = qw/ SayBye /; our $language = "US-English"; $A::first = "Alpha"; sub SayHello {"hello from package A\n"}; sub SayBye {"Goodbye.\n"} package B; require Exporter; our @ISA = qw/ Exporter A /; our @EXPORT = qw/ SayBye /; $B::first = "Bravo"; sub SayHello {"hello from package B\n"}; sub SayByeBye {SayBye().SayBye();} package main; ### begin_: get stuff from A print("$A::first\n"); print A::SayHello(); print("$language\n"); print A::SayBye(); print "\n---------------------\n"; ### begin_: get stuff from B print("$B::first\n"); print B::SayHello(); print("$language\n"); print B::SayBye(); ### <-- ERROR Undefined subroutine &B::SayBye print B::SayByeBye(); print "\n---------------------\n";
janitored by ybiC: Correct mis-spelling in nodetitle: s/berebones/barebones/
In reply to ISA with packages ... A barebones minimal example by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |