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

I just created a new virtual machine under VMWare 4.5 and installed SuSE Linux 9.1 on it. I didn't make any changes to the PERL or Apache2 installation options. A lot of scripts that have always worked perfectly (on previous installs of SuSE and other Linux flavors both as virtual machines and on "real" machines) are now broken. Every time I use "use" to include a package that is not part of the PERL installation, PERL claims it can't find the .pm file. For example, foo.pl is located in /home/mydir/perl/foo. In foo.pl I eval "use Mypackage" and when I run the script through a browser, $@ contains the error "Can't find Mypackage.pm in @INC..." The listing of paths contained in @INC _does_ include /home/mydir/perl/foo. This is happening with every script I've written. In the scripts, I add the path to the script files to @INC and when the error is generated, I see that @INC _does_ contain the directory where the supposedly missing .pm definitely _does_ reside. So, the path is in @INC and the file in in the path but PERL swears it can't find the file.

Standard PERL packages load just fine using "use" and the scripts all work if I run them from the command line as long as I am in the directory that contains the script files. If I run the script from another path or through a browser, I get the @INC error every time for every package I try to use.

Replies are listed 'Best First'.
Re: Odd "use" problem
by borisz (Canon) on Jun 11, 2004 at 13:10 UTC
    How do you add a path to @INC? try it with:
    use lib q{/my/path};
    or
    BEGIN { unshift @INC, "/my/path" }
    or set the environment var with
    export PERL5LIB="/My/Path"
    Boris

      I wonder if there is an easy way to include ${HOME}/lib by default for all users... so using 'use lib (glob("~/lib"))[0]' is unnecessary

      No one has seen what you have seen, and until that happens, we're all going to think that you're nuts. - Jack O'Neil, Stargate SG-1

        Put
        test -r $HOME/lib && export PERL5LIB=$HOME/lib
        in your /etc/profile or /etc/bash.bashrc whatever is executed for every users shell. untested ...
        Boris
      I have used both of the methods you mentioned, the only real difference being that when using "use lib" I have always used
      use lib qw(/a/path /another/path);

      The path is showing up in @INC and the files is in the path but PERL chokes on it every time.

Re: Odd "use" problem
by pelagic (Priest) on Jun 11, 2004 at 13:20 UTC
    Might sound obvious, but anyway:
    have you checked file permissions?

    pelagic
      Yeah, that occured to me and I checked it out. I thought that when I copied the whole directory off the old box I might have screwed something up but all the permissions are fine.