Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl use/require abolute 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.

Edit: Clarification:

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.

like image 400
700 Software Avatar asked Feb 13 '13 13:02

700 Software


People also ask

What is the difference between use and require in Perl?

use is evaluated at compile-time, require at run-time. use implicitly calls the import method of the module being loaded, require does not. use excepts arguments in addition to the bareword (to be passed to import), require does not.

What is the use of use in Perl?

A require statement is evaluated at execution time. If the VERSION argument is present between Module and LIST, then the use will call the VERSION method in class Module with the given version as an argument. The default VERSION method, inherited from the UNIVERSAL class.

What is require keyword in Perl?

Description. This function then it demands that the script requires the specified version of Perl in order to continue if EXPR is numeric. If EXPR or $_ are not numeric, it assumes that the name is the name of a library file to be included. You cannot include the same file with this function twice.


1 Answers

You can use this :

use lib '/path/to/Perl_module_dir'; # can be both relative or absolute
use my_own_lib;

You can modify @INC by yourself (temporarily, no fear, that's what use lib does too) :

BEGIN{ @INC = ( '/path/to/Perl_module_dir', @INC ); } # relative or absolute too
use my_own_lib;
like image 97
Gilles Quenot Avatar answered Oct 05 '22 23:10

Gilles Quenot