SWAT /

PERL Module Search Path

Reading

Outdoors

Games

Hobbies

LEGO

Food

Code

Events

Nook

sidebar

PERL Module Search Path

PERL Module Search Path

Sometimes it's a hassle to install Perl modules into its global search path, e.g. if you just want to stuff some subroutines into a file. Here are some ways of dealing with that. Both are based around the notion that the module is in the same directory as the calling script or somewhere similar, e.g. a sub-directory.

Create an absolute path for the module:

 $resfile=$0;
 $resfile =~ s/\/[^\/]+\.pl$//;
 require $resfile . "/module.pl";

Or push the script directory into the search path:

 $resfile=$0;
 $resfile =~ s/\/[^\/]+\.pl$//;
 push @INC, $resfile;
 require "module.pl";

Note that in their most basic form, modules are just perl scripts that evaluate to 1. Usually you do this to define subroutines. An example is here.

Recent Changes (All) | Edit SideBar Page last modified on December 11, 2006, at 04:45 PM Edit Page | Page History