Skip to main content

Checking Perl Library Path and Modifying it

It is contained in an array @INC, so checking it would be as easy as printing that array. One can add or subtract items to this array to include of exclude some libraries using array manipulating tools like shift/unshift/chop/pop/push/splice/ ... . Here is a script demonstrating that.



!#/usr/bin/perl -w
#Prints Perl library path and modifies it:
print "Default Perl library path:\n@INC\n";
push(@INC, "/home/user/lib/perl");
print "New Perl library path:\n@INC\n";


And the output was:

Default Perl library path:

/etc/perl /usr/local/lib/perl/5.8.8 /usr/local/share/perl/5.8.8 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.8 /usr/share/perl/5.8 /usr/local/lib/site_perl .


New Perl library path:


/etc/perl /usr/local/lib/perl/5.8.8 /usr/local/share/perl/5.8.8 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.8 /usr/share/perl/5.8 /usr/local/lib/site_perl . /home/user/lib/perl

BTW: I brushed up on Perl basics from this great resource:
http://www.pageresource.com/cgirec/http://www.pageresource.com/cgirec/index2.htm

Comments