nysus has asked for the wisdom of the Perl Monks concerning the following question:

I've been working on this for a couple of hours and getting nowhere. I want to add two different paths to PERL5LIB. Here's what I have right now:

case "$PERL5LIB:" in *"/usr/local/lib/perl5/site_perl:"*) :;; *) PERL5LIB="/usr/local/lib/perl5/site_perl:$PERL5LIB";; esac export PERL5LIB case "$PERL5LIB:" in *"/Users/me/perl/perl_lib:"*) :;; *) PERL5LIB="/Users/me/perl/perl_lib:$PERL5LIB";; esac export PERL5LIB

When I do perl -V, it looks good:

/Users/me/perl/perl_lib /usr/local/lib/perl5/site_perl /Users/me/perl5/perlbrew/perls/perl-5.24.1/lib/site_perl/5.24.4/da +rwin-2level /Users/me/perl5/perlbrew/perls/perl-5.24.1/lib/site_perl/5.24.4 /Users/me/perl5/perlbrew/perls/perl-5.24.1/lib/5.24.4/darwin-2leve +l /Users/me/perl5/perlbrew/perls/perl-5.24.1/lib/5.24.4 /Users/me/perl5/perlbrew/perls/perl-5.24.1/lib/site_perl/5.24.1/da +rwin-2level /Users/me/perl5/perlbrew/perls/perl-5.24.1/lib/site_perl/5.24.1 /Users/me/perl5/perlbrew/perls/perl-5.24.1/lib/site_perl .

However, when I try to run a command, I get this: Cannot load config file: couldn't open /Users/me/perl/perl_lib:/usr/local/lib/perl5/site_perl/

The directories somehow got concatenated together. I don't know much about bash scripting or setting ENV variables. Any tips are appreciated. Thanks

Update: I have perlbrew installed which I think might be part of the problem.

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks

Replies are listed 'Best First'.
Re: How do you export more than one path to PERL5LIB
by hippo (Archbishop) on Aug 16, 2018 at 07:49 UTC
    Cannot load config file: couldn't open /Users/me/perl/perl_lib:/usr/local/lib/perl5/site_perl/

    That's not a problem with the setting of $PERL5LIB, that's a problem with how your perl script is using it. Since you haven't shown your script I can't help you further with that.

    BTW, there is no effect in exporting the same variable twice in sh/bash.

    Update: just for completeness, here's a demo showing multiple entries in $PERL5LIB.

    use strict; use warnings; use Path::Tiny; use Test::More tests => 3; chdir '/'; # In case you have . in @INC my $mod = path ('/tmp')->child ('ZZZZZ.pm'); $mod->spew ('package ZZZZZ;1;'); ok ! system ("PERL5LIB=/tmp:/foo perl -e 'use ZZZZZ;'"), 'First in pat +h'; ok ! system ("PERL5LIB=/foo:/tmp perl -e 'use ZZZZZ;'"), 'Second in pa +th'; ok system ("PERL5LIB=/foo:/bar perl -e 'use ZZZZZ;'"), 'Not in path' +; $mod->remove;

      That was it! Thanks so much. I was tearing my hair out. My code made very bad assumptions about what was in $ENV{'PERL5LIB'}. Lesson learned.

      $PM = "Perl Monk's";
      $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest";
      $nysus = $PM . ' ' . $MCF;
      Click here if you love Perl Monks

Re: How do you export more than one path to PERL5LIB
by anonymized user 468275 (Curate) on Aug 16, 2018 at 11:23 UTC
    You seem to want to update PERL5LIB with some paths if they are not there already. But your bash code is too far away from achieving this and it seems easier in Perl e.g.:
    #/bin/sh # ... export PERL5LIB=`perl -e ' use strict; use warnings; my @addinc = ("/usr/local/lib/perl5/site_perl", "/Users/me/perl/perl_lib" ); my %inc = map { $_, 1 } split (/\:/, $ENV{PERL5LIB}); for (@addinc) { # this was just updated $inc{$_} or print "$_:"; } print "$ENV{PERL5LIB}\n"; '`

    One world, one people

      With perlbrew, add to .bash_profile: export PERL5LIB=`perl -e '($p,$v)=split("-",$ENV{PERLBREW_PERL}); print "$ENV{HOME}/perl5/perlbrew/perls/perl-$v/lib/site_perl/$v/darwin-2level"' `
Re: How do you export more than one path to PERL5LIB
by clueless newbie (Curate) on Aug 16, 2018 at 11:36 UTC
    C:\Users\me>set PERL5LIB PERL5LIB=c:/;c:/users C:\Users\me>perl -M5.10.0 -e "say $_ for @INC" c:/ c:/users P:/perl/site/lib/MSWin32-x64-multi-thread P:/perl/site/lib P:/perl/lib .