简体   繁体   English

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

[英]How to split perl programm over multiple files

How do I use functionality written in a different file, but not located in an @INC location, but relative to the main executable?如何使用在不同文件中编写但不位于@INC位置但相对于主可执行文件的功能? I want to be able to distribute the entire directory and have it be executable everywhere (assuming third-party libraries are already installed).我希望能够分发整个目录并让它在任何地方都可以执行(假设已经安装了第三方库)。

You can use FindBin to get the location of your main executable and lib to add directories to your @INC that are based on your main directory.您可以使用 FindBin 获取主可执行文件的位置,并使用lib将目录添加到基于主目录的@INC

A common example would be if your libraries were in a /lib directory below the directory that contains your main program.一个常见的例子是,如果您的库位于包含主程序的目录下的/lib目录中。

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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