Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: Know a perl's -I flag from perl?

by Anonymous Monk
on Dec 15, 2012 at 10:45 UTC ( [id://1008969]=note: print w/replies, xml ) Need Help??

in reply to Read a perl's -I flag from perl?

@INC is @INC

Replies are listed 'Best First'.
Re^2: Know a perl's -I flag from perl?
by petr999 (Acolyte) on Dec 15, 2012 at 14:27 UTC


    You are very right Anoymous.

    And I can accept the point of view that perl interpreter flags should not be controlled from perl source.

    Actually I can imagine that there can be another kind of perl interpreter that can have the different flags an/or not to be a binary at all (e. g., a binary library) and it may not accept namely the -I flag.

    But I think the task is quite straightforward to take those condireations not as seriously as I can.

    It's all just about to run the binary from make test or prove.

    I believe it's not a problem for you to suggest another way to supply the libraries path for perl binary to run from tests, if you have any.

    Thank you.

      The purpose of -I is to populate @INC

      You don't need the original -I flags, you have @INC

        But @INC can be altered at run time. Consider that your default @INC is just:


        You run perl -I/eg/custom

        Now @INC is:</c>

        /eg/custom /eg/lib

        Imagine that contains use mylibs which loads /eg/custom/ This module itself tinkers with @INC at run-time, adding another path at the front.

        /corporate/lib /eg/custom /eg/lib

        Now you want to launch another Perl process via system(), so what do you do? Something like:

        my @incs = map { "-I$_" } @INC; system($^X, @incs, '');

        So when the other script starts, it will start with this in @INC:

        /corporate/lib /eg/custom /eg/lib

        Now let's imagine that also does use mylibs. Rather than that loading /eg/custom/, it might now load /corporate/lib/, which is perhaps an older version of the mylibs package which behaves differently to how we wanted.

        Granted this is a rare situation, but there do exist packages along these lines; packages that exist entirely to manipulate @INC, such as local::lib. Combining these libraries with system($^X) can get you into a merry little pickle.

        perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1008969]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (2)
As of 2024-07-14 07:13 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.