Home > Archive > PERL Miscellaneous > October 2004 > How to use relative path for a module
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
How to use relative path for a module
|
|
| dn_perl@hotmail.com 2004-10-27, 8:56 pm |
| Is it (possible / advisable) to use relative path for a module?
I install 3 directories under a location specified by my client.
The client may specify /apps/home or /home/usr/myproduct or whatever
as the location where I should install my 3 directories.
My directories are : myapp, mylib, myhelp.
Let us say they are installed under /apps/home. One env variable
which the user is required to set is $MYAPP_HOME="/apps/home/myapp" .
The dir /apps/home/mylib contains a module : dir_list.pm .
I want the perl script /apps/home/myhelp/option01 to use dir_list.pm .
How can I do so using 'use dir_list' construct?
"use ../mylib/dir_list" gives syntax error.
Thanks in advance.
| |
| Sherm Pendley 2004-10-27, 8:56 pm |
| dn_perl@hotmail.com wrote:
> I install 3 directories under a location specified by my client.
One option is to have the installer script - if you're using one - alter
the 'use lib' line in your scripts.
> Let us say they are installed under /apps/home. One env variable
> which the user is required to set is $MYAPP_HOME="/apps/home/myapp" .
If you're asking your users to set environment variables anyway, you
could simply have them set PERL5LIB to point to /apps/home/mylib.
Another option would be to do this:
use lib $ENV{'MYAPP_HOME'} . '/../mylib';
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
| |
| David Efflandt 2004-10-27, 8:56 pm |
| On 27 Oct 2004 13:46:10 -0700, dn_perl@hotmail.com <dn_perl@hotmail.com> wrote:
> Is it (possible / advisable) to use relative path for a module?
>
> I install 3 directories under a location specified by my client.
> The client may specify /apps/home or /home/usr/myproduct or whatever
> as the location where I should install my 3 directories.
>
> My directories are : myapp, mylib, myhelp.
> Let us say they are installed under /apps/home. One env variable
> which the user is required to set is $MYAPP_HOME="/apps/home/myapp" .
> The dir /apps/home/mylib contains a module : dir_list.pm .
> I want the perl script /apps/home/myhelp/option01 to use dir_list.pm .
> How can I do so using 'use dir_list' construct?
> "use ../mylib/dir_list" gives syntax error.
You could do it realive to the current working directory "./":
use lib "./mylib"; # puts this 1st in @INC
use "dir_list";
However, you have to make sure the current working dir is what you think
it is. For example, in CGI called as SSI, the working dir is the dir of
the SSI page, not the CGI script.
|
|
|
|
|