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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.