How to use relative path for a module

D

dn_perl

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.
 
S

Sherm Pendley

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--
 
D

David Efflandt

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,981
Messages
2,570,188
Members
46,731
Latest member
MarcyGipso

Latest Threads

Top