calling perl subroutine in shell script

风流意气都作罢 提交于 2019-12-04 15:18:55

It's hard to say what went wrong not knowing what's in MyModule.pm.

@INC looks ok (. is in the list, so there should be no problem with locating MyModule.pm in current directory).

Here's a minimal example that works the way you described. Hope it helps.

$ cat SomeModule.pm 
package SomeModule;

sub testsub
{
  return "it works\n";
}

1;
$ VAL=`perl -I. -MSomeModule -e 'print SomeModule::testsub'`
$ echo $VAL
it works

Another way to load the module would be:

$ perl -e 'require "./SomeModule.pm"; print SomeModule::testsub()'
it works
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!