Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Relative Module Path

by Anneq (Vicar)
on Aug 02, 2004 at 01:50 UTC ( #379171=note: print w/ replies, xml ) Need Help??


in reply to Relative Module Path

After running into this problem several times, I've standardized how I place script and module files in each project. Basically in my project directory, I have a sub-directory for scripts (e.g., cgi-bin) and a sub-directory for my modules (my_lib). Then I can include the following code in any script and it always finds my modules.

#--------------------------------------------------------------------- +-- # Portably Include My Perl Modules #--------------------------------------------------------------------- +-- use Cwd; use File::Spec; my $dir; BEGIN { # Prepare lib path $dir = Cwd->getcwd; # Get directory path of script or get web doc +root my @dirs = File::Spec->splitdir( $dir ); # Split path into array pop @dirs; # Take off last directory (e.g., public_html, cgi-bin,. +..) # Put'em togeth & add modules dir $dir = File::Spec->catdir( @dirs, "my_lib"); unshift(@INC, $dir) if (-d $dir); # Incl. my lib if it exists }

Hope that helps,

Anne


Comment on Re: Relative Module Path
Download Code
Re^2: Relative Module Path
by wfsp (Abbot) on Aug 02, 2004 at 07:22 UTC
    Excellent. Iíve had a long fight with this too. Many thanks. Worth adding to snippets?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://379171]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (8)
As of 2014-12-25 13:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (160 votes), past polls