perlabsolute-path

use/require absolute path?


If I have a .pm file, is there a way I can use it, without placing it on my @INC path? I think that would be clearer in my particular use case - clearer than using relative paths or adding this directory to @INC.

I was hoping to avoid the necessity to iterate through every item in @INC, and instead specify directly which file I am interested in. For example, in Node.JS, require('something') will search the list of paths, but require('/specific/something') will go directly where I tell it to.

In Perl, I am not certain that this is the same functionality found in require, but it seems to work.

However, use statements require barewords. That has left me a little stumped on how to enter an absolute path.


Solution

  • As per discussion in comments, I would suggest using require itself. Like below,

    require "pathto/module/Newmodule.pm";
    
    Newmodule::firstSub();
    

    Also you can use other options as below

    use lib 'pathto/module';
    use Newmodule;