Packages & Modules
What are Perl Modules?
- A Perl module is a reusable package defined in a library
file whose name is the same as the name of the package (with a .pm on the end)
- A Perl module file called "Foo.pm" might contain statements like this
package Foo;
sub bar { print "Hello $_[0]\n" }
sub blat { print "World $_[0]\n" }
1;
- The functions
require
and
use
will load a module
- Both use the list of search paths in @INC to find
the module (you may modify it!)
- Both call the eval function to process the code
- The 1; causes eval to evaluate to TRUE (and thus not fail)