4

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.
Håkon Hægland
  • 39,012
  • 21
  • 81
  • 174
Kip
  • 63
  • 6
  • And what does `perl -e'require String::Approx;'` output? – ikegami Jul 02 '21 at 22:02
  • (In the future, please post text as text, not an image.) – ikegami Jul 02 '21 at 22:02
  • @ikegami It doesn't do anything... – Kip Jul 02 '21 at 22:05
  • Is this macOS ? – Håkon Hægland Jul 02 '21 at 22:16
  • *"The module I want (String::Approx) is installed"* : What is the output of `perl -MString::Approx -E'say $INC{"String/Approx.pm"}'` ? – Håkon Hægland Jul 02 '21 at 22:17
  • *"But I am getting the error Can't locate String/Approx.pm in @INC"* : When do you get this error? – Håkon Hægland Jul 02 '21 at 22:19
  • 1
    I think the `./myScript.pl` is using the system perl, and not the perlbrew perl. That explains why it cannot find the module. Is there a [shebang](https://en.wikipedia.org/wiki/Shebang_(Unix)#:~:text=In%20computing%2C%20a%20shebang%20is,bang%2C%20or%20hash%2Dpling.) in that script? Alternatively, to avoid interpreting the shebang, you can run the script as `perl myScript.pl` instead of `myScript.pl` – Håkon Hægland Jul 02 '21 at 22:32
  • @ Håkon Hægland Yes, macOS Big Sur. Output is `/Users/kip/perl5/perlbrew/perls/perl-5.33.9/lib/site_perl/5.33.9/darwin-2level/String/Approx.pm`. The error happens at `use String::Approx 'amatch';` – Kip Jul 02 '21 at 22:33
  • @ Håkon Hægland ```perl myScript.pl``` worked. Wow, I have spent several days on this problem. Are you able to explain what's happening? – Kip Jul 02 '21 at 22:40

1 Answers1

4

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
    
mob
  • 117,087
  • 18
  • 149
  • 283