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


I run a perl binary with a perl interpreter from my perl program with system.

Both perl binary I run with system and my perl program that runs it require the library (module) for inclusion. The 'parent' perl source gets it with perl's -I flag. I assume it is always 'all right' and my module is always found.

What I want is to pass that -I flag to the 'child' program as it is/they are specified for the 'parent' program.

I think to formulate this task as 'to get all of the flags supplied for the current Perl interpreter' should be okay as I can get the matching qr{^-I} flags then.

The problem is: how can I get my Perl's interpreter's runtime flags? perlvar was no much help to me. Where should this info be found?

In details, I'd like to test my bin/stuff run from my t/555-test.t. By far the test will be supplied the '-I' flags from both 'prove' and 'make test' as well as need no the '-I' flags after being installed so I'd like to have my '-I' flag for my Perl interpreter to run it in the system() exactly the same as for my test being performed.

Can this be done?

Thank you.

Replies are listed 'Best First'.
Re: Know a perl's -I flag from perl?
by tobyink (Canon) on Dec 15, 2012 at 11:10 UTC


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


      Pleased! Thanks! will try.

      Thank you.

Re: Know a perl's -I flag from perl?
by Anonymous Monk on Dec 15, 2012 at 10:45 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