In the kernel itself, the file extension you use does not matter how perl interprets these files.
However, placing modules in .pm files following a specific directory structure that follows the package name provides convenience. So, if you have a module Example::Plot::FourD , and you put it in the directory Example/Plot/FourD.pm on the path to @INC , then use and require will be correct when considering the package name, as in use Example::Plot::FourD .
The file should return true as the last statement to indicate the successful execution of any initialization code, so usually end the file with 1; if you are not sure that it will return true otherwise. But itβs better to just put 1; if you add more operators.
If EXPR is a simple word, require implies the extension β.pmβ and replaces β::β with β/β in the file name for you to make loading standard modules easier. This form of loading modules is not subject to change your namespace.
All use is to determine the file name from the provided package name, require in the BEGIN block and call import in the package. Nothing prevents you from using use , but performing these steps manually.
For example, below I put the package Example::Plot::FourD into a file named t.pl , loaded it into a script file in the s.pl file.
C:\Temp> cat t.pl package Example::Plot::FourD; use strict; use warnings; sub new { bless {} => shift } sub something { print "something\n" } "Example::Plot::FourD" C:\Temp> cat s.pl
This example shows that the module files should not end with 1 , any true value will do.
Sinan ΓnΓΌr Aug 04 '10 at 12:41 2010-08-04 12:41
source share