LPM: Module question

Rich Bowen rbowen at rcbowen.com
Tue Jan 25 20:57:38 CST 2000


David Hempy wrote:
> 
> At 03:23 PM 1/25/2000 -0500, you wrote:
> >
> >you can do a
> >use lib './';
> 
> Thanks for the tip, Matt.  This still had problems when run as CGI, but
> told me know what I was looking for.
> 
> My final solution comes from the Cookbook, Chapter 12.7. Keeping Your Own
> Module Directory:
> 
> >...suppose you have a program called /wherever/spectre/myprog that needs to
> >look in
> >/wherever/spectre for its modules, but you don't want to hardcode that path.
> >
> >use FindBin;
> >use lib $FindBin::Bin;
> 
> Thus, my code to include pressroom.pm in the same directory ends up looking
> like:
> 
> use FindBin;
> use lib $FindBin::Bin;
> use pressroom;          #page footers and other common subs.

Or, if you want to do it the really ugly way:

BEGIN{($_=$0)=~s![\\/][^\\/]+$!!;push at INC,$_}

Isn't that fun! That is, take the path of the currently executing
program, and then remove a slash, followed by some stuff that's not a
slash, off the end of it. And push that onto @INC. I suppose you really
want to unshift it onto @INC, but it does not matter a whole lot.

See http://www.rcbowen.com/imho/perl_cwd_iis.html which came out of a
thread on the hwg-servers mailing list.

Rich
-- 
http://www.ApacheUnleashed.com/
Lexington Perl Mongers - http://lexington.pm.org/
PGP Key - http://www.rcbowen.com/pgp.txt



More information about the Lexington-pm mailing list