如何将 perl 程序拆分为多个文件

How to split perl programm over multiple files

如何使用写在不同文件中但不位于 @INC 位置但相对于主可执行文件的功能?我希望能够分发整个目录并使其在任何地方都可执行(假设已经安装了第三方库)。

您可以使用 FindBin 获取 location of your main executable and lib 以将基于主目录的目录添加到 @INC

一个常见的例子是,如果您的库位于包含主程序的目录下的 /lib 目录中。

use FindBin '$RealBin';
use lib "$RealBin/lib";

# You can then load your own modules from /lib
use My::Module;