如何设置 CGI 脚本模块的 Perl 包含路径?

发布于 2024-07-09 09:46:37 字数 213 浏览 5 评论 0 原文

我的主机上的 ~/perl 中安装了多个 Perl 模块,如何将它们添加到 Perl 模块路径? 设置PERL5LIBunshift@INC的路径肯定有效,但是当作为CGI脚本运行并且< code>@INC 方式不太可移植。 有没有更好的办法? 这一定是一个常见问题,我是否遗漏了什么?

I’ve got several Perl modules installed on my hosting machine in ~/perl, how do I add them to Perl module path? Setting PERL5LIB or unshifting the paths to @INC surely works, but the environment variable does not help when running as a CGI script and the @INC way is not very portable. Is there a better way? This has to be a common problem, am I missing something?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

老旧海报 2024-07-16 09:46:37

在我看来,一种更简洁的方法是:

use lib "/path/" ;  

还有其他有趣且好的方法可以在这里找到:

http://www.slideshare.net/pfig/cpan-training-presentation/

另外,回复:CGI脚本,您可以为您的CGI环境定义PERL5LIB路径,这仅取决于您的虚拟主机。

某些 Web 主机允许对 CGI 环境的环境变量进行特定控制,您只需设置它们,其他 Web 主机可能有一个“允许”列表,允许在启动时可见的变量出现在本地范围内。

可能有助于了解如何在您的特定 HTTP 服务器上执行此操作。

如果设置 ENV 不符合您的口味,还有一个选项: local::lib

自动搜索一些预定义的路径。

A cleaner way to do it imo is :

use lib "/path/" ;  

there are other interesting and good ways to do it that can be found here:

http://www.slideshare.net/pfig/cpan-training-presentation/

Also, re: CGI scripts, you CAN define PERL5LIB paths for your CGI Env, it just depends on your webhost.

Some Webhosts permit specific control of env variables for the CGI Enviroment, and you have to just set them, others may have a "permit" list that allows variables visible at start time appear in local scope.

May help to read up on how to do this on your specific HTTP server.

There is one more option, if setting ENV is not to your taste: local::lib

Which searches some predefined paths automatically.

分開簡單 2024-07-16 09:46:37

PERL5LIB 对于 CGI 脚本来说效果很好。 您只需在正确的位置设置变量,例如服务器配置。 您使用哪个网络服务器? 对于 Apache,我使用 mod_env 中的 SetEnv 指令。

@INC 是可移植的。 您输入的路径可能在每台计算机上都不相同,但变量本身不应该有问题。

您是否阅读过 perlfaq8 中的常见问题解答条目:

PERL5LIB works just fine for CGI scripts. You just have to set the variable in the right place, such as the server configuration. Which webserver are you using? For Apache, I use the SetEnv directive from mod_env.

@INC is portable. The paths you put in there may not be the same on every machine, but you shouldn't have a problem the with variable itself.

Have you read the FAQ entries in perlfaq8:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文