Hans has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I'm a newbie when it comes to perl and as such my knowledge is limited. So please for give me if I sound vague. My problem is that, I been trying to install and configure and opensource (Symphero) ecommerce package ( perl based ) for sometime now and without success onto my ISP server. Part of this problem is due to the fact that it requires specific modules from http://www.cpan.org to be compiled and installed. But due to access/permission i'm not able to install them to the appropriate directories. Having searched through the cpan site, I found that by entering :- perl -e 'print join("\n",@INC)' This should print the hard-coded @INC which perl is looking for. Through my telnet login I tried this and got:- /usr/lib/perl5/5.00503/i386-linux /usr/lib/perl5/5.00503 /usr/lib/perl5/site_perl/5.005/i386-linux /usr/lib/perl5/site_perl/5.005 No reference is made to my home directory. Upon further search of the CPAN site i found that symlinks, aliases, or shortcuts can be created. But the techies on the ISP hosting company helpdesk inform me this is not possible with '@INC'. But however they do mention that Perl has commands for adding extra paths to @INC which I could use at the top of the scripts and have the module local to my home directory. My problem here is being new to perl I don't know what i'm looking for or how to do this. Please can anybody assist in resolving this problems. Thanks to all in advance. Hansraj

Replies are listed 'Best First'.
RE: How to Add path to @INC
by ferrency (Deacon) on Jul 28, 2000 at 21:17 UTC
    The easy answer is:

    use lib qw(/my/path/to/add/);
    This adds directories to @INC at compile-time, so they're valid in subsequent use statements. Try perldoc lib for more information on this.

    The longer answer:

    You could do this to add things to @INC:

    push @INC, '/my/path/to/add';
    because, @INC is just a Perl array, nothing special. However, use statements are executed at compile time, not at runtime, so if you simply push onto the array, @INC won't be changed until runtime, and your use still won't find what it's looking for.

    Pushing things directly onto @INC would work if you're just doing require, which happens at runtime. But the short answer is best: just  use lib and you'll be happy.

    Alan

      The only way to get @INC changes to be noticed at "compile" time would be to put them in a BEGIN block. But yah, 'use lib' is much preferred.
Re: How to Add path to @INC
by athomason (Curate) on Jul 28, 2000 at 21:16 UTC
    Installing a module to a user directory is covered in this faq. Basically, when compiling the module yourself, just add PREFIX=/directory to the command line when running Makefile.PL. I've never tried to do this through CPAN.pm, so I'm not sure if you can do it that way. Once you've installed the module, you have a number of options for telling Perl where to look for it. First, like you've heard, is to add the path to the @INC variable via something like push @INC, "/directory";. My preferred method is insteaduse lib "/directory;, which lets Perl check for the module at compile time and probably save you some headaches down the road. There's also an environment variable to do the same thing, but I've never used that, and I'm sure someone else will suggest it ;-).
Re: How to Add path to @INC
by KM (Priest) on Jul 28, 2000 at 21:18 UTC
    use lib qw(.); # Will add your cwd to @INC use lib qw(. /path/to/my/home /some/other/dir); # will add those dirs +to @INC
    Command line to do it would be:
    perl -I/path/to/include script

    Check out:
    perldoc lib
    perldoc perlrun

    Cheers,
    KM

Re: How to Add path to @INC
by princepawn (Parson) on Jul 28, 2000 at 21:46 UTC
    And of course dont forget the PERL5LIB environmental variable, which wasnt even mentioned in Camel 2. I have yet to look at Camel 3. To some, Perl is an art form. To others it is a religion. What is it to you?