BM> Quoth (e-mail address removed):
>>
>> Is there a way to capture the perl options in a command like this:
>> perl -w -S script.pl
>>
>> @ARGV holds the options script.pl & onwards. What I want are the the
>> perl options (in this case:
>> -w, -S ) also.
BM> Some of them (like -w) show up as magic variables: see perldoc perlvar.
BM> I don't believe that applies to -S.
and a better question is why do you want them? i have never seen anyone
ask for these in 16 years of hacking perl. what purpose could you have
to want this info? those are options to make perl do certain things and
there are plenty of them. also perl can use environment variables to set
some things that options can also do. you can't tell where the settings
came from. i smell a major XY problem here where your real problem is X
but you are asking about your solution which is Y.
uri
The problem that I am facing is the following: I have a perl script
(run_Calibre_Command.plx)
which i want to ensure that everybody in our team pick the identical
versions of
"perl" irrespective of his .cshrc/.tcshrc settings. Towards that end,
we use the famous
eval 'exec perl -w -S -- "$0" ${1+"$@"}'
if 0;
dictum copied from the Camel book.
But I have modified that a little & it looks somewhat like this:
:
eval '
PATH=/tool/all/wrappers/bin${PATH:+:}${PATH-}; export PATH
_perl_wrapper="5.8.8/2007"; export _perl_wrapper
exec perl -w -S -- "$0" ${1+"$@"}
'
if 0;
use strict;
use warnings;
local $\ = "\n";
......
......
__END__
Now what is happening is that if I invoke the perl script from the
command line as:
% run_Calibre_Command.plx [script options follow here]
Then whoever uses it gets to invoke the same version of perl.
However, if I were to invoke the perl script from the command line as:
% perl [perl options] run_Calibre_Command.plx [script options
follow here]
then the eval 'exec perl ...' scheme breaks down since depending on
the user's
..cshrc/.tcshrc settings that particular version of perl binary & it's
attendant
library files get invoked. To overcome this I wrote a brief code
inside the BEGIN
block that does esentially what the eval 'exec ...' is doing.
BEGIN{
$ENV{PATH} = "/tool/all/wrappers/bin:$ENV{PATH}"
unless $ENV{PATH} =~ m{\A/tool/all/wrappers/bin[:]}xms;
if ( !exists $ENV{_perl_wrapper} || !defined $ENV{_perl_wrapper} ||
$ENV{_perl_wrapper} ne '5.8.8/2007' ) {
local ($", $\) = (" ", "\n");
print {*STDERR} "realigning perl path...";
$ENV{_perl_wrapper} = '5.8.8/2007';
exec("PATH=$ENV{PATH} _perl_wrapper=$ENV{_perl_wrapper} perl -w -
S \"@ARGV\" -- $0"); # <======== PROBLEM HERE
}
}
##################################
As you can see we are not able to capture the perl options using this
way as @ARGV just looks at the perl script options
not the options to perl.
In essence I just want to re-fire the perl command line as is, but
with the new perl binary.
% perl [perl options] run_Calibre_Command.plx [script options]
How would we do it, if at all it's feasible
-- Rakesh