The perlmod documentation states
All Perl module files have the extension .pm
. The use
operator assumes this so you don't have to spell out "Module.pm"
in quotes. This also helps to differentiate new modules from old .pl
and .ph
files. Module names are also capitalized unless they're functioning as pragmas; pragmas are in effect compiler directives, and are sometimes called "pragmatic modules" (or even "pragmata" if you're a classicist).
The two statements:
require SomeModule;
require "SomeModule.pm";
differ from each other in two ways. In the first case, any double colons in the module name, such as Some::Module
, are translated into your system's directory separator, usually "/".
...
Perl packages may be nested inside other package names, so we can have package names containing ::
. But if we used that package name directly as a filename it would make for unwieldy or impossible filenames on some systems. Therefore, if a module's name is, say, Text::Soundex
, then its definition is actually found in the library file Text/Soundex.pm.
The special @INC
array contains directories to be searched for modules:
@INC
The array @INC
contains the list of places that the do EXPR
, require
, or use
constructs look for their library files. It initially consists of the arguments to any -I
command-line switches, followed by the default Perl library, probably /usr/local/lib/perl
, followed by "."
, to represent the current directory. ("."
will not be appended if taint checks are enabled, either by -T
or by -t
.) If you need to modify this at runtime, you should use the use lib
pragma to get the machine-dependent library properly loaded also:
use lib '/mypath/libdir/';
use SomeMod;