How to use relative path for a module

Discussion in 'Perl Misc' started by dn_perl@hotmail.com, Oct 27, 2004.

  1. Guest

    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.
     
    , Oct 27, 2004
    #1
    1. Advertising

  2. 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
     
    Sherm Pendley, Oct 27, 2004
    #2
    1. Advertising

  3. On 27 Oct 2004 13:46:10 -0700, <> 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.
     
    David Efflandt, Oct 28, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ronald Fischer

    Struts: module relative path puzzle

    Ronald Fischer, Jul 25, 2003, in forum: Java
    Replies:
    0
    Views:
    1,047
    Ronald Fischer
    Jul 25, 2003
  2. Matt
    Replies:
    3
    Views:
    19,567
    Sudsy
    Jul 8, 2004
  3. Thomas Guettler
    Replies:
    3
    Views:
    761
    Andrei
    Oct 27, 2003
  4. Oren
    Replies:
    1
    Views:
    551
    Michael D. Ober
    Apr 29, 2007
  5. Nigel Wilkinson
    Replies:
    2
    Views:
    389
    Nigel Wilkinson
    Jul 25, 2005
Loading...

Share This Page