Tuesday, July 19, 2016

How to use Custom Perl Modules

Perl modules are easy to create and are used a library which you can reuse in another program or modules. However, for use it you need to do a bit of tweak in the environment, so that the interpreter can find the perl module.

@INC is the array, which works like CLASSPATH, in case you are familiar with Java. so, in the beginning of your code you need add the path where to find the perl modules you are using,


BEGIN {
        unshift(@INC, '/lib');


 # considering my perl module is located in /lib folder, relative to the current perl file

Now, @INC is an array which contains the paths of libraries, in case perl it is .pm files. And, unshift is used to append the path in the begining.

So, this code tweak make Perl interpreter aware of the path and you Perl code runs perfectly fine.  



No comments:

Post a Comment

Prototype

Prototype is another creation pattern. Intent:  - Intent is to create objects by cloning existing instance  - Specify the kinds of obj...