简体   繁体   中英

Perl -M will not find a hardcoded path to a module

Background

Inside a chsell script, I am invoking a subroutine from a perl module and saving its result to a variable in the following manner :

set result =`perl -M/some/hard/coded/path/lib.pm=theFunction -e 'theFunction( $A_VARIABLE_ARGUMENT )'`

Despite the fact that I explicitly specify the module, my script throws this error:

Module name required with -M option

Question

How do I invoke a hardcoded module with perl's -M option?

You cannot, as the -M option is translated to a use statement which takes only module names, not paths. However, you can add the path to be the first module search path using the -I option. Modules are searched relative to each search path by translating them like Foo::Bar -> Foo/Bar.pm .

perl -I/home/hard/coded/path -Mlib=theFunction

As a note, you should definitely not call your module or package lib , because this is an important core module (in fact, it's what -I is using here).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM