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

Well, no luck with chatterbox, so I guess I ask it here.

When building perl (I'm actually installing with plenv), how do I remove curdir (i.e., ".") from the default @INC? I don't mean no lib "." or anything like that, I mean perl -V shouldn't show it at the bottom.

You can stop reading here unless you like other people's whining.

For some reason, I can't make DDG or any other search engine return anything except how to add things to @INC at run time. Is that really a thing people don't know how to do? It's in the FAQ for Wall's sake! If you want to *add* directories during Configure http://search.cpan.org/perldoc/INSTALL tells you all about it and a million other things. Yet not a word on *removing* directories.

Why is curdir even included in the default @INC in the first place? How often is your cwd a perl library root! I'm thinking... approximately never. It seems like a security risk to me. It definitely messes up plenv list-modules (i.e., ExtUtils::Installed->new->modules()), which now has to look through whatever your cwd is and all it's descendants for .packlist files. Even if you happen to be located in a directory with thousands of subdirectories and millions of files: "YTF is this list-modules command not returning instantly whenever I'm on my NAS NFS mount?!?" Even if you're in a project directory with multiple local::lib installs: "YTF is list-modules telling me every module in every project is installed, when none of them are installed at this level?!?" Even if you're in $HOME (where plenv lives): "YTF is list-modules telling me every module I've installed for *any* version of perl is installed for *every* version of perl I have?!?"

Ridiculous. Yet I can't find anyone else having this issue because search engines only want to tell me about adding to @INC at runtime. Sigh. I even looked through the Configure script and couldn't find anything about leaving out directories. Hopefully some monk knows the answer. Thanks!

Replies are listed 'Best First'.
Re: Configuring default @INC
by syphilis (Archbishop) on Mar 01, 2017 at 01:30 UTC
    I mean perl -V shouldn't show it at the bottom

    1) Create a file called (eg) no_dot.pm:
    package no_dot; # Assuming that '.' is at the end of @INC # Otherwise amend code accordingly BEGIN{pop @INC}; 1;
    2) Place no_dot.pm in your $INC[0] folder.
    3)Set the environment variable PERL5OPT to -Mno_dot
    4) Run perl -V and observe that the last @INC entry (which is '.' for me) no longer appears.
    5) Clear PERL5OPT to return to original @INC.

    Cheers,
    Rob
      heh... just using -M-lib=. would be better, but I specifically said I didn't want to do that. Thanks anyway.
        just using -M-lib=. would be better, but I specifically said I didn't want to do that

        Yes, setting PERL5OPT to -M-lib=. is a simpler solution - and one that I hadn't really thought about.

        Cheers,
        Rob
Re: Configuring default @INC
by stevieb (Canon) on Mar 01, 2017 at 00:26 UTC

    You seem angry. This is particularly unfriendly towards a site that offers help for free, on the very day you signed up.

    Perhaps the reason you can't find anyone else with this problem is because they've thought about it methodically, and realized it wasn't one.

    It would be appropriate for you to explain your problem calmly, with steps for us to reproduce it exactly, so others can evaluate it. Not everyone follows ChatterBox, and those that do, don't follow it constantly.

    Please edit your question with your original problem, steps to reproduce it, and the outcome you'd like to see (including @INC before and after).

    You may want to note that this "security issue" has been recognized, and '.' will not be part of @INC in the upcoming 5.26 release of Perl. It was removed in the 5.25 development track, so since Perl's inception, this must not have been an issue. Did you hear about it somewhere? Is that what the complaint is about?

    By the way, Welcome to Perlmonks!

Re: Configuring default @INC
by 1nickt (Canon) on Mar 01, 2017 at 01:41 UTC

    Why is curdir even included in the default @INC in the first place? How often is your cwd a perl library root! I'm thinking... approximately never.

    I use the fact that '.' is the last entry in @INC all the time, when developing my own modules, when a test needs a custom library, or when I've forked an existing module to work on it.


    The way forward always starts with a minimal test.
Re: Configuring default @INC
by Anonymous Monk on Mar 01, 2017 at 01:14 UTC

    read the source

        Oh, well, that sucks. Have to go to the source code and even then only in the very latest development version. At least I know now, thanks for the link.
Re: Configuring default @INC
by ikegami (Patriarch) on Mar 01, 2017 at 17:39 UTC

    Perl itself won't install without . in @INC (for now, unless you're compiling the latest from the repo).

Re: Configuring default @INC
by Anonymous Monk on Mar 01, 2017 at 21:58 UTC
    "It seems like a security risk to me ... Yet I can't find anyone else having this issue because ..."

    Because it is not an issue.

    "When building perl (I'm actually installing with plenv) ..."

    And this is your mistake. Use perlbrew.