Perl for Newbies - Part 3 - Modules and ObjectsPerl ModulesLoading Modules and Importing their Functions

3.2. Loading Modules and Importing their Functions

In order to have access to a module from within your script (or from within another module) you can use the use directive followed by the name of the module as it is deduced from its path. Here's an example: assume that the file "" is this:

# This is the file

package MyModule;

use strict;
use warnings;

sub a_function
    print "Hello, World!\n";


And this is your script:


use strict;
use warnings;

use MyModule;

# Notice that we use "::" to call the function out of the module.

That way, the program will print "Hello, World!" on the screen.

Written by Shlomi Fish