Perlbrew 找不到@INC

Perlbrew can't find @INC

我认为 perlbrew 已正确安装并使用了正确的 @INC。我切换到 perlbrew。我想要的模块 (String::Approx) 已安装。我在 ~/.bash_profile.

中有来源 ~/perl5/perlbrew/etc/bashrc

但我收到错误 Can't locate String/Approx.pm in @INC :

$ which perl
/Users/kip/perl5/perlbrew/perls/perl-5.33.9/bin/perl
$ perlbrew info
Current perl:
  Name: perl-5.33.9
  Path: /Users/kip/perl5/perlbrew/perls/perl-5.33.9/bin/perl
  Config: -de -Dprefix=/Users/kip/perl5/perlbrew/perls/perl-5.33.9 -Dusedevel -Aeval:scriptdir=/Users/kip/perl5/perlbrew/perls/perl-5.33.9/bin
  Compiled at: May  3 2021 10:04:48

perlbrew:
  version: 0.92
  ENV:
    PERLBREW_ROOT: /Users/kip/perl5/perlbrew
    PERLBREW_HOME: /Users/kip/.perlbrew
    PERLBREW_PATH: /Users/kip/perl5/perlbrew/bin:/Users/kip/perl5/perlbrew/perls/perl-5.33.9/bin
    PERLBREW_MANPATH: /Users/kip/perl5/perlbrew/perls/perl-5.33.9/man
$ perlbrew list-modules
App::cpanminus
PerlIO::gzip
String::Approx
install
$ perl -E 'say for @INC'
/Users/kip/perl5/perlbrew/perls/perl-5.33.9/lib/site_perl/5.33.9/darwin-2level
/Users/kip/perl5/perlbrew/perls/perl-5.33.9/lib/site_perl/5.33.9
/Users/kip/perl5/perlbrew/perls/perl-5.33.9/lib/5.33.9/darwin-2level
/Users/kip/perl5/perlbrew/perls/perl-5.33.9/lib/5.33.9

这是我尝试 运行 我的脚本(为便于阅读而格式化)时出现的特定错误消息。 @INC 系统好像还在搜索中?

Can't locate String/Approx.pm in @INC (you may need to install the String::Approx module) 
(@INC contains: /Library/Perl/5.30/darwin-thread-multi-2level 
/Library/Perl/5.30 /Network/Library/Perl/5.30/darwin-thread-multi-2level 
/Network/Library/Perl/5.30 
/Library/Perl/Updates/5.30.2 
/System/Library/Perl/5.30/darwin-thread-multi-2level 
/System/Library/Perl/5.30 
/System/Library/Perl/Extras/5.30/darwin-thread-multi-2level 

/System/Library/Perl/Extras/5.30) at ./myScript.pl line 21.

运行 myscript.pl 因为 ./myscript.pl 似乎正在使用系统 perl (v5.30)。也许该文件中有一个指向系统 perl 的 shebang 行。如果是这种情况,那么调用 ./myscript.pl 将始终引用 shebang 行中指定的程序,而不是 perlbrew 将您的环境设置为什么。

解决方案:

  1. 明确使用perl调用脚本

    $ perl myscript.pl    # this
    $ ./myscript.pl       # and not this
    
  2. 更新您的 shebang 行以使用“当前”perl。其中一项或多项可能有效:

    #!perl
    #!/usr/bin/env perl