1

I'd like to override some perl modules from a perl tool installed via conda. Perl is v5.26.2 installed via conda-forge. However, I cannot overwrite any scripts which are located in the same directory as $SCRIPT because perl always prepends the location of the script to the module directories:

/opt/anaconda/envs/vep-99/share/ensembl-vep-99.2-0/modules
/opt/anaconda/envs/vep-99/share/ensembl-vep-99.2-0
/home/user/.local/lib/perl5/lib/perl5/x86_64-linux-thread-multi
/home/user/.local/lib/perl5/lib/perl5
/opt/anaconda/envs/vep-99/lib/site_perl/5.26.2/x86_64-linux-thread-multi
/opt/anaconda/envs/vep-99/lib/site_perl/5.26.2
/opt/anaconda/envs/vep-99/lib/5.26.2/x86_64-linux-thread-multi
/opt/anaconda/envs/vep-99/lib/5.26.2
.

I now did a very ugly hack which simply changes the working directory for perl:

#!/bin/bash                                                                                                                                                                                                                                                                                                                                                                                 
                                                                                                                                                                                                                                                                                                                                                                                             
SCRIPT="${SCRIPT:-vep}"
SCRIPT_DIR="$(dirname $(realpath $(which $SCRIPT)))"
 
export PERL5LIB="$PERL5LIB:$SCRIPT_DIR:$SCRIPT_DIR/modules"

cd /
 
# fake script location to be in the current working directory
cat $(which $SCRIPT) | perl $@

This results in the following @INC:

//modules
/
/home/user/.local/lib/perl5/lib/perl5/x86_64-linux-thread-multi
/home/user/.local/lib/perl5/lib/perl5
/opt/anaconda/envs/vep-99/share/ensembl-vep-99.2-0
/opt/anaconda/envs/vep-99/share/ensembl-vep-99.2-0/modules
/opt/anaconda/envs/vep-99/lib/site_perl/5.26.2/x86_64-linux-thread-multi
/opt/anaconda/envs/vep-99/lib/site_perl/5.26.2
/opt/anaconda/envs/vep-99/lib/5.26.2/x86_64-linux-thread-multi
/opt/anaconda/envs/vep-99/lib/5.26.2
.

This technically works, but there is still /, //modules and . in the include path. Is there a way to get rid of that?

7
  • 2
    A default build of perl only includes its installation directories in the include path, and from 5.26.0 onwards doesn't include '.'. If your perl has other paths, that's either due to the perl being built with non-standard build args, or you're calling it with extra paths in PERL5LIB or similar. or your script is adding extra include paths. Commented Jan 31, 2022 at 17:29
  • 2
    "cat $(which $SCRIPT) | perl $@" : What is the purpose of this command? It seems to pipe the source code lines of the file found by running which $SCRIPT to perl. It is not clear why you do that Commented Jan 31, 2022 at 18:09
  • @Dave my perl version is v5.26.2 installed from conda-forge. My problem is that Perl always adds dirname $SCRIPT as well as $(dirname $SCRIPT)/module as the top-most entries in @INC. By piping the script into perl, I fake the location of the script to be $PWD. Does this make sense to you @Hakon? Commented Feb 1, 2022 at 18:26
  • As Ikegami says, it isn't perl adding those locations, it's you - via the setting of the PERL5LIB environment variable. Commented Feb 2, 2022 at 8:23
  • @DaveMitchell I think I'm missing something obvious here... After the export PERL5LIB I get PERL5LIB=/home/user/[...]:/opt/anaconda/envs/vep-99/share/[...]:/opt/anaconda/envs/vep-99/lib/[...]. However, inside the Perl process I get something like @INC=/modules:/:/home/user/[...]:/opt/anaconda/envs/vep-99/share/[...]:/opt/anaconda/envs/vep-99/lib/[...]. I.e. it prepends the current working directory, not? Commented Feb 4, 2022 at 15:47

1 Answer 1

1

It's the following that's adding the first two directories:

export PERL5LIB="$PERL5LIB:$SCRIPT_DIR:$SCRIPT_DIR/modules"

Instead of adding cd /, just remove or comment out that line.


As for ., it's hardcoded up Perl 5.26 (released in 2017) and absent from then on. Removing it would require running something like the following:

# Remove relative paths from `@INC` (on unix systems).
BEGIN { @INC = grep m{^/}, @INC; }

But, since . is last in @INC, it doesn't hinder your attempts to override modules.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your answer @ikegami. Unfortunately the problem is not which directories are added but rather the order in which they are being added. In detail, perl v5.26.2 installed via conda-forge always adds the script location as the topmost entries in @INC and "." as the last entry as it seems. This way, I cannot override a module which is located in the same directory as the $SCRIPT.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.