FreeKB - How to create a custom module in Perl
How to create a custom module in Perl

Home > Search > How-to

A custom module can be created for code that needs to be used in numerous Perl scripts. For example, let's say you have numerous Perl scripts that create an SSH connection to other servers. 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 /path/to/custom/perl/modules/


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

print "Welcome to my Perl script"


Now, in all of your Perl scripts, use the module.

use lib "/path/to/custom/perl/modules";
use exampleModule;


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

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 in the box below so that we can be sure you are a human.