Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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

by tobyink (Abbot)
on Dec 19, 2012 at 14:58 UTC ( #1009572=note: print w/ replies, xml ) Need Help??

in reply to Re^3: Know a perl's -I flag from perl?
in thread Read a perl's -I flag from perl?

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'

Comment on Re^4: Know a perl's -I flag from perl?
Select or Download Code
Replies are listed 'Best First'.
Re^5: Know a perl's -I flag from perl?
by Anonymous Monk on Dec 21, 2012 at 03:59 UTC


    So before your script diddles @INC, preserve it?

    use constant FINC => [ @INC ]; use lib ...;

    And if you're worried about that, then worry about PERLLIB/PERL5LIB/PERL5OPTS...

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (14)
As of 2015-10-06 15:32 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (154 votes), past polls