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

Let's say you wrote a module that's invoked from the command line to start a long running process. For some reason you want to restart the process on specific occasions and need to reconstruct the original command line for exec. Does the module have a way to know the values of any -I or -M switches it was invoked with? I don't know of any special variables that provide that information. I did figure out how to derive the value(s) of -I by comparing the contents of @INC to the value of 4 %Config variables:
perl -le 'print for reverse @INC'
/Users/u/perl5/perlbrew/perls/perl-5.42.0/lib/5.42.0
/Users/u/perl5/perlbrew/perls/perl-5.42.0/lib/5.42.0/darwin-2level
/Users/u/perl5/perlbrew/perls/perl-5.42.0/lib/site_perl/5.42.0
/Users/u/perl5/perlbrew/perls/perl-5.42.0/lib/site_perl/5.42.0/darwin-2level
perl -MConfig -le 'print $Config{$_} for qw[privlib archlib sitelib si +tearch]'
/Users/u/perl5/perlbrew/perls/perl-5.42.0/lib/5.42.0
/Users/u/perl5/perlbrew/perls/perl-5.42.0/lib/5.42.0/darwin-2level
/Users/u/perl5/perlbrew/perls/perl-5.42.0/lib/site_perl/5.42.0
/Users/u/perl5/perlbrew/perls/perl-5.42.0/lib/site_perl/5.42.0/darwin-2level
Is this a standard thing on all perl installations? I can hack up an -M switch detector by looking for things in %INC that don't match the default paths in @INC. Is there an easier way or is this the easiest way? Thanks!

Replies are listed 'Best First'.
Re: Finding the value of -I and -M command line switches
by tobyink (Canon) on May 21, 2026 at 12:08 UTC