macosperlperlbrew

Perlbrew can't find @INC


I think perlbrew is properly installed and using the correct @INC. I switched to perlbrew. The module I want (String::Approx) is installed. I have sources ~/perl5/perlbrew/etc/bashrc in ~/.bash_profile.

But I am getting the error 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

This is the specific error message when I try to run my script (formatted for readability). It looks like the system @INC is still being searched?

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.

Solution

  • Running myscript.pl as ./myscript.pl appears to be using the system perl (v5.30). Perhaps there is a shebang line in that file that points to the system perl. If that is the case, then calling ./myscript.pl will always refer to the program specified in the shebang line, not what perlbrew has set your environment to.

    Solutions:

    1. Use perl explicitly to invoke the script

      $ perl myscript.pl    # this
      $ ./myscript.pl       # and not this
      
    2. Update your shebang line to use the "current" perl. One or more of these might work:

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