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
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).