0

这是我的项目:

assembler/
    asm.pl               # Main entry point
    instructions.pm
    support.pm
build.sh

---- assembler/asm.pl ----
...
use instructions;
...

---- assembler/instructions.pm ----
...
use support;
...

我希望build.sh包含如下一行:

perl assembler/asm.pl $1

尝试使用相关模块时asm.pl,找不到它们。这条线有效,但感觉肮脏和可耻:

cd assembler; perl asm.pl ../$1; cd ..

正确的执行方式是asm.pl什么?我希望直接从任何其他任意位置执行位于文件系统上任何位置的程序,例如

$ cd /some/dumb/path
$ /path/to/the/project/build.sh /another/goofy/path.asm
4

1 回答 1

4

我认为问题在于 perl 试图找到与您正在执行的路径相关的库。这就是为什么运行 cd 首先修复它。您的另一个选择是告诉 perl 它可以在哪里找到文件。您可以使用 PERL5LIB 环境变量或使用 -I 开关来执行此操作。这应该这样做:

perl -I./assmbler/ assembler/asm.pl $1
于 2012-11-29T23:53:13.483 回答