Reputation: 3838
Can we load perl module without ".pm" file extension?
Can we have perl module with some other file extension such as "dll", "so" or "lib"
Just curious to know, how only "pm" files can be loaded as package/module in perl.
Upvotes: 2
Views: 893
Reputation:
You can load any file you want with require "file_name";
, with or without extension. The only requirement is that the file is syntactically valid Perl and that it returns a true value in order to indicate that loading the module was successful;
The usual use Module;
is basically only a shortcut for
BEGIN {
require Module;
Module->import();
}
and require Module;
(note the missing "..."
around the module name!) looks for "Module.pm"
in all the directories listed in @INC
.
So: require
with a string loads any file, require
with a Bareword
looks for "Bareword.pm"
in @INC
.
Upvotes: 7