Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove entry from @INC

Tags:

terminal

perl

Is it possible to remove an entry from @INC from the command line?

I know export PERL5LIB=/path/file.pm can be used to add them, but can they be removed in a similar fashion?

EDIT:
I know that directories are not typically removed from @INC, but in my case (and maybe yours, if you are here for help) I added an entry of my own that I needed removed not only because it was a custom entry, but also because it specified a file (incorrect usage of @INC) and not a folder.

Additional Info:
The export command was executed from the command line, not from a script.

like image 317
Ctrl S Avatar asked May 31 '26 20:05

Ctrl S


1 Answers

You could use the no lib pragma from the command line with perl -M-lib=...:

$ PERL5LIB=/tmp/foo perl -le 'print for @INC'
/tmp/foo
... normal @INC entries ...
$ PERL5LIB=/tmp/foo perl -M-lib=/tmp/foo -le 'print for @INC'
... normal @INC entries ...

Update: Based on the wording of the question, I assumed that you had a system where you had set PERL5LIB, and were asking how to exclude entries once in a while, only for specific runs of perl ("from the command line"). That's what the above does: The effect of no lib used on the command line is only temporary for that run of perl.

But the discussion in the comments revealed that it was the opposite: you had run export PERL5LIB=... "from the command line" (the effect of which is only temporary the current session/shell), and wanted to undo that change - for which the solution is either to run export PERL5LIB= (setting a new value overwrites the previous one, export is not like adding elements to a list, it just sets a new value), or to simply log out and back in again.

If you had set PERL5LIB in a place like the .profile or .bashrc files, then you would need to edit those and comment out or delete the entries you don't want, and log out and back in again.

like image 178
haukex Avatar answered Jun 02 '26 19:06

haukex