Perl:将当前目录包含到@INC?

标签 perl

我正在将一些网站从旧网络服务器迁移到新网络服务器。旧的网络服务器使用 Perl 5.8,新的网络服务器使用 Perl 5.28。两者之间的区别之一是在 5.8 上,脚本运行的目录默认包含在 @INC 中。 5.28 并非如此。这意味着“需要”本地文件的 cgi 脚本会抛出错误。

我知道我可以将这些行添加到脚本中来解决问题:

use FindBin qw( $RealBin );
use lib $RealBin;

但问题在于,我需要为很多脚本执行此操作。

有没有办法一次性将所有脚本的当前目录 (.) 添加到 @INC?最好仅供 www 数据用户使用?

最佳答案

export PERL_USE_UNSAFE_INC=1

根据 perldelta :

PERL_USE_UNSAFE_INC

There is a new environment variable recognised by the perl interpreter. If this variable has the value 1 when the perl interpreter starts up, then "." will be automatically appended to @INC (except under tainting).

This allows you restore the old perl interpreter behaviour on a case-by-case basis. But note that this is intended to be a temporary crutch, and this feature will likely be removed in some future perl version. It is currently set by the cpan utility and Test::Harness to ease installation of CPAN modules which have not been updated to handle the lack of dot. Once again, don't use this unless you are sure that this will not reintroduce any security concerns.

不过,我会听取建议并尽量避免设置此设置。也许在困境中,正如您所处的那样,这可能没问题,因为您已经处于安全风险之中;但我肯定会尽快更新文件并取消设置此变量。

关于Perl:将当前目录包含到@INC?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60683284/

相关文章:

regex - 如何在 perl 中打印特定格式的数组?

perl - 如何为所有传入的 URL 创建通用处理程序?

perl - "…/auto/List/Util/Util.so: undefined symbol: PL_stack_sp at …/XSLoader.pm"仅当在 Travis CI 上使用 CGI::Test _and_ 运行测试套件时

perl - 为什么 Perl 允许在 unblessed 数据结构上调用 coderefs?

perl - 将非必要的 .pl 文件放在哪里?

arrays - 如何避免将重复值插入 Perl 数组

perl - 我可以找出给定文件句柄具有哪些Perl IO层吗?

perl - 如何为文件中存在的每个字符串分配行号

perl - Moose 类的依赖注入(inject)

perl - 以预定义格式打印输出 Perl