This sequence is completely fine. Main can "use Common" and MyLib can "use Common" too. No problem. Common.pm will be "used" and say any BEGIN{} statements will be run on first occurrence of "use Common", after that no code in Common.pm is run. Do not put .pm after the name in the "use" statement.

You are doing something with Exporter if you are exporting names from a .pm package module. Package is a name space concept. You don't have to export a name but if you don't, you will have to use the fully qualified package name for it, FOO:some_function_4, etc.

A sort of generic header for a FOO package module in the FOO package name space looks like this...(name this file FOO.pm). It is possible to have multiple "packages" within one Perl file. I strongly recommend against this practice.

use strict; use warnings; package FOO; use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $VERSION); use Exporter; our $VERSION=1.0; our @ISA = qw(Exporter); our @EXPORT = qw( some_func_name1 some_func_name2 ); our @EXPORT_OK = qw(some_optional_func_name3);
The "use FOO"; statement does not imply an inheritance hierarchy. Exporter just puts symbols into a symbol table. The form above is more like a 'C' include statement - not exactly, but similar in concept. To fiddle with OO inheritance, I figure that you need to mess with @ISA. This does inherit from Exporter, but that is what you have to do in order for you to export names into from the FOO package name space so that other modules can see them.

In reply to Re: use directives by Marshall
in thread use directives by bob_dobalina

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.