FreeKB - Perl (Scripting) Create your own module
Perl (Scripting) - Create your own module

A custom module can be created for code that needs to be used in numerous Perl scripts. As a sort of silly but easy example, let's say you want to print a welcome message at the beginning of each of your Perl scripts. First, create a module.

~]# touch /usr/share/perl/modules/


In the module, add your welcome message, such as "Welcome to my Perl script."

print "Welcome to my Perl script\n";


Here is how you would use the module.

use strict;
use warnings;
use lib "/usr/share/perl/modules";
use foo;


Now, when running your Perl modules, "Welcome to my Perl script" will be printed to the console.

If something is not working as expected, add the following to your Perl script to validate that the directory that contains your module is included.

print join ( "\n", @INC );


Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter ded94 in the box below so that we can be sure you are a human.


Web design by yours truely - me, myself, and I   |   |