They look superficially similar, but semantically they mean very different things. The first line (with some modifications)
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.use Some_Module qw( blah );
The second line (again with some modifications)
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.use base qw( Some_Package );
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:
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".use some_pragma qw( foobar );
Pragmatic modules are very common too (e.g. strict and warnings). In fact
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".use base qw( 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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |