What is the Difference between .pm
(Perl module) and .pl
(Perl script) file?
Please also tell me why we return 1
from file. If return 2 or anything else, it's not generating any error, so why do we return 1
from Perl module?
What is the Difference between .pm
(Perl module) and .pl
(Perl script) file?
Please also tell me why we return 1
from file. If return 2 or anything else, it's not generating any error, so why do we return 1
from Perl module?
At the very core, the file extension you use makes no difference as to how
perl
interprets those files.However, putting modules in
.pm
files following a certain directory structure that follows the package name provides a convenience. So, if you have a moduleExample::Plot::FourD
and you put it in a directoryExample/Plot/FourD.pm
in a path in your@INC
, thenuse
andrequire
will do the right thing when given the package name as inuse Example::Plot::FourD
.All
use
does is to figure out the filename from the package name provided,require
it in aBEGIN
block and invokeimport
on the package. There is nothing preventing you from not usinguse
but taking those steps manually.For example, below I put the
Example::Plot::FourD
package in a file calledt.pl
, loaded it in a script in files.pl
.This example shows that module files do not have to end in
1
, any true value will do.A .pl is a single script.
In .pm (Perl Module) you have functions that you can use from other Perl scripts: