In my understanding
ENV_PERL5LIB is not as important for Perl scripts as
ENV_PATH is for Bash scripts.
Perl gets the paths of the modules folders from its
@INC array. The
@INC is specific for each Perl installation, and it is known to Perl no matter if you run the Perl script via KM or otherwise.
A use-case for
ENV_PERL5LIB in KM:
It is not uncommon that you have two or more Perl installations on your computer, for example:
- The Perl that comes preinstalled with macOS (currently ver 5.18.2)
/usr/bin/perl; let’s call this System’s Perl
- An up-to-date Perl (currently ver 5.24.1)
/usr/local/bin/perl; let’s call this Main Perl
So, let’s say I have installed the Pandoc module for my Main Perl installation.
Now I run this script via KM:
This will throw no errors, since the path of the Pandoc module is in the
@INC of my Main Perl.
Then I run this script:
The System’s Perl will complain that it can’t find the Pandoc module, because it’s not part of its
Can't locate Pandoc.pm in @INC (you may need to install the Pandoc module)
The safest thing would be to install the Pandoc module for the System’s Perl. (“safest” because not every module version works with every Perl version.)
But, I could also force the System’s Perl to look for the module at a specified path. I can do this either by saying:
#!/usr/bin/perl -I <path/to/a/module/folder>
Or – instead of the modified shebang – I could add the module’s path to the
ENV_PERL5LIB variable in KM, which makes Perl add that path to its
Please note, I’m not a full-time Perl user, so it may be that there are other (or better) use-cases for the variable which are not obvious to me.
A good read is this Stackoverflow post.