Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Dear esteemed PerlMonks

I am wrestinlg with the following issue (which may be a trivial one): how do you export functions from a package, which is not the first one in a module file? I've been searching the documentation and the Net, and can't seem to find an answer.
Here is an example:

# Name of this file: pack_A.pm package pack_A; require Exporter; @ISA = qw {Exporter}; @EXPORT = qw {first second}; sub first { } sub second { } 1; #end package pack_A; package pack_B; sub third { } sub fourth { } 1; #end package pack_B;
In the main script, I would like to use package pack_B, which sits lower in the file: pack_A.pm.
It turns out that it's not that simple. If you add the subroutines 'third' and 'fourth' to @EXPORT,
@EXPORT = qw {first second third fourth};
then in your main script, when you go:
use pack_A;
and call the 'third' sub, it will complain:
undefined subroutine &pack_A::third ...etc
(You can't go:
use pack_B;
since the interpreter looks for the file specified in "use". In other words, it will look for the module pack_B.pm, which does not exist).

Your advice will be appreciated.
Many TIA - Helen


In reply to How to export a package sitting lower in a module? by HelenCr

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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others taking refuge in the Monastery: (6)
    As of 2017-10-22 13:57 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      My fridge is mostly full of:

















      Results (273 votes). Check out past polls.

      Notices?