Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Removing entries from @INC

by perlancar (Hermit)
on Feb 24, 2022 at 14:40 UTC ( #11141617=perlquestion: print w/replies, xml ) Need Help??

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

Is there a way to do no lib from the command-line option (the opposite of -I or -Mlib=...)? I want to remove entries from @INC, or to be more exact I want to set @INC to an exactt list of directories. Preferably without the use of -e or other non-core modules.

Replies are listed 'Best First'.
Re: Removing entries from @INC
by Fletch (Bishop) on Feb 24, 2022 at 14:56 UTC

    As documented in perlrun if the first character of the library name after -M / -m is a dash the use is treated as no instead: perl -M-lib=/TO/REMOVE ...

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

      Thanks! Now that you pointed it out, I vaguely remember reading about this years ago.
Re: Removing entries from @INC
by ikegami (Patriarch) on Feb 24, 2022 at 19:33 UTC

    I want to set @INC to an exactly list of directories

    eh? You've surely done something wrong along the way if you need to do this.

    Why do you think you need to remove entries from @INC?

      I have a perl script that starts another instance of perl interpreter, and I want the latter to inherit the original script's @INC.

      The actual case is I'm testing (prove -l) a script in a Perl distribution which starts another perl script that requires a module in the current distribution. The latter script would fail to find the module because its @INC does not contain lib. Now in this specific case I can just add -Ilib option to the latter script's invocation when detecting some environment variable, but I'm curious about the more generic solution.

        Have script #1 add to PERL5LIB whatever it adds to @INC.

Re: Removing entries from @INC
by LanX (Saint) on Feb 24, 2022 at 14:44 UTC
    did you try ... ?
    BEGIN { @INC = YOUR_LIST; }

    ... on top of your script?

    update

    > from the command-line option

    Oops, I missed that, sorry.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

      printf ' package cleanlib; sub import { @INC = ( ); } 1 ' >cleanlib.pm perl -Mlib=. -Mcleanlib -Mlib=... ...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11141617]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2023-11-29 11:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?