• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 259
  • Last Modified:

Problem with .pm file

Is there a way to have a perl script find a .pm file, when you don't have access to the directories that @INC includes? (Other than ".")

I have created a script that loads a .pm file that contains all sorts of variables. I do not presently have access to any of the directories that perl looks into in it's @INC list, with the exception of ".". I change directories while running the script, and run other scripts, that also load the same .pm file. When I run the main script, from the directory that contains the .pm file in question, it runs fine, while the other sub-scripts die, because they can not find the .pm file.

Is it possible to load a .pm file with an absolute path? Or, does one have to always be able to load the .pm into a directory that @INC includes? Or can one define @INC for the user, in their log in script?

I have already modified the user's path to include the directory that has the scripts. I am not sure how to tell perl to modify @INC, as a non-admin user...
1 Solution
You can use the lib pragma to add a path to the @INC array.

For example, lets say the full path to your module is: /home/stakor/lib (your module is in that directory).  The lib statement in your scripts would be:
use lib '/home/stakor/lib';
use YourModule;  # load your module

Open in new window

You can also use the local::lib pragma to accomplish the same thing.

The lib pragma is part of the perl core, so it will be available for you to use.  The local::lib pragma is not part of the core, so it may or may not already be installed.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now