Alex Rivera | Logout

How do I load a file relative to a module path?

Asked 2009-09-23T00:52:58.210
10

I don't know how to do one thing in Perl and I feel I am doing something fundamentally wrong.

I am doing a larger project, so I split the task into different modules. I put the modules into the project directory, in the "modules/" subdirectory, and added this directory to PERL5LIB and PERLLIB.

All of these modules use some configuration, saved in external file in the main project directory - "../configure.yaml" if you look at it from the module file perspective.

But, right now, when I use module through "use", all relative paths in the module are taken as from the current directory of the script using these modules, not from the directory of the module itself. Not even when I use FindBin or anything.

How do I load a file, relative from the module path? Is that even possible / advisable?

Edit
Report

1 Answer

8

The global %INC table contains an entry for every module you have use'd or require'd, associated with the place that Perl found that module.

use YAML;
print $INC{"YAML.pm"};

>> /usr/lib/perl5/site_perl/5.8/YAML.pm

Is that more helpful?

answered 2009-09-23T01:42:29.633

Your Answer