Why re-invent the wheel? There are numerous libraries and modules available for Perl that will save you much time
and effort in accomplishing many common tasks. In writing your own programs, you may also wish to divide them
into modules to reduce complexity. Most programers find that the divide-and-conquer strategy of seperating a program's
tasks into smaller sub-components makes the job much easier and understandable.
One category of modules called pragmas directs the Perl compiler to operate in different ways. You can think of
them as similar to Perl's command-line switches but more advanced.
required my_other_script.pl;
use Module; use Module LIST; use Module qw(first second third);
where LIST represents functions or sets of functions to be imported from the Module.
Note: The qw() function (quoted words) takes a list of arguments, wraps each in quotes, and puts them in
a list. It's used as a shortcut. The following are equivalent:
@List = ('first', 'second', 'third');
@List = qw(first second third);
The special variable @INC contains a list of directories for where to look for perl modules and libraries.
When perl is installed, the locations of the installed modules are stored in @INC. You can modify @INC in your
scripts to specify additional places to look for modules. By default, the current path is also included in @INC.
package directoryname::modulename; # any functions or variables following this statement inside the module # must be specified by directoryname::modulename::variablename
When variables or functions in a module are imported into your script, it eliminates the need for using the
long prefixes to specify them. (Their names are imported into the current global namespace of your script.) You
typically import the variables and functions from a module that you wish to use in your current script. Some of
the variables and functions of a module will be imported automatically, depending on the module, whenever the module
is used.
Example:
use CGI qw(:standard); # Use the CGI module and import all functions and variables associated with the :standard label.
use strict; # turn on strict pragma
my $a = 3; # define and intialize variable $a
my ($b, $c, $d, @my_list); # define these variables
$new_list = (3,4,5); # throws an error because
# $new_list has not been defined
if($a){ # the variable $a can be used