in reply to Modules on a Unix server

The shebang line tells the shell what program (Perl) to use to execute the contents of the file, but modules may live in a different directory. Once you find that directory, you can tell Perl to look for modules in it using the use lib statement:

use lib '/path/to/modules/';

(Do this before any of your other use statements.) You could also directly manipulate the @INC array, which tells Perl where to look for modules, but I personally consider the use lib syntax to be cleaner and more self-documenting.

As for finding the module directory in the first place: You can probably use something like find -iname strict.pm. (Someone who's more of a Unix guru than I may have a better suggestion). You'll also need to be sure that the modules you intend to use are actually installed on your server, and download them if not. If your admins won't put these into a convenient directory you can always just create your own local module directory and use lib it.

Replies are listed 'Best First'.
Re: Re: Modules on a Unix server
by Anonymous Monk on May 14, 2002 at 15:38 UTC
    Please advise what I am doing wrong. I was given an area where we store our modules and it still has problems.
    use lib '/export/home/jones/perl/lib/perl5/site_perl/LWP/Simple.pm';


    Output message from my vir.pl script:
    vir.pl[6]: use: not found vir.pl[8]: =: not found vir.pl[13]: syntax error at line 13 : `(' unexpected


    My script does work on my NT but this module problem on Unix is another issue. Please advise if I am using the lib correctly?
      From the output you supplied, it sounds as if the initial shebang line is not correctly executing the Perl interpreter in the first place. Are you sure that line is correct in your script? You might try a really simple test program to see:

      #!/path/to/perl print "Hello, world";

      If you've got the shebang right, this should just output Hello, world when you execute it.

      As for use lib, what you probably really want to do is this:

      use lib '/export/home/jones/perl/lib/perl5/site_perl/'; use LWP::Simple;

      The first line basically says "when I write use Something, make sure you look in /export/home/jones/perl/lib/perl5/site_perl/ to find Something.pm."

      The second line actually uses the LWP::Simple module (appending lwp/Simple.pm to the path specified by use lib).

        Thanks seattlejohn for helping me. I am now up and working with this module. Thanks again!!