perlmod文档状态
所有 Perl 模块文件都有扩展名.pm
. 运营商假设这一点,use
因此您不必"Module.pm"
在引号中拼写出来。这也有助于将新模块与旧模块.pl
和.ph
文件区分开来。模块名称也是大写的,除非它们用作编译指示;pragma 实际上是编译器指令,有时称为“实用模块”(如果您是古典主义者,甚至称为“pragmata”)。
两种说法:
require SomeModule;
require "SomeModule.pm";
在两个方面彼此不同。在第一种情况下,模块名称中的任何双冒号,例如Some::Module
,都被翻译成系统的目录分隔符,通常是“/”。
...
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;