They look superficially similar, but semantically they mean very different things. The first line (with some modifications)

use Some_Module qw( blah );
loads the module in the file Some_Module.pm (in some directory listed in @INC), and then invokes Some_Module->import( 'blah' ), which typically (though not always) has the effect of importing blah into the current namespace. And all this happens at compile time.

The second line (again with some modifications)

use base qw( Some_Package );
has the effect of adding the string 'Some_Package' to the @ISA array of the current package. This amounts to turning the current package into a subclass of Some_Package. This too happens at compile time.

The first line represents a far more general situation than does the second one. Lines like the second line are meaningful only when defining an OO class, while lines like the first one are ubiquitous, since they are used to load Perl code defined in other files.

Here's a third variant:

use some_pragma qw( foobar );
which looks very similar to the first line discussed above, but its primary intent is to provide compiler directives (possibly parametrized by some argument, such as the string 'foobar' in this example). Such "compiler directive" modules are called "pragmas" or "pragmatic modules".

Pragmatic modules are very common too (e.g. strict and warnings). In fact

use base qw( Some_Package );
happens to be an example of this, in which the pragma is base, the parameter is the string 'Some_Package', and the resulting compiler directive is something like "treat the current package as a subclass of Some_Package".

the lowliest monk


In reply to Re: How to use a 'Use' by tlm
in thread How to use a 'Use' by palette

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.