Reputation: 83
I'm aware a script can retrieve all the command line arguments passed to it through ARGV, i.e.:
# test.pl
print "$ARGV[0]\n";
print "$ARGV[1]\n";
print "$ARGV[2]\n";
## perl ./test.pl one two three
one
two
three
In the above example, the command line arguments passed to the test.pl
script are "one", "two" and "three".
Now, suppose I run the following command:
## perl -d:DumpTrace test.pl one two three
or
## perl -c test.pl one two three
How can I tell from within the operations of the test.pl
script that the options -c
or -d:DumpTrace
were passed to the perl interpreter?
I'm looking for a method that will identify when options are passed to the perl interpreter during the execution of a script:
if "-c" was used in the execution of `test.pl` script {
print "perl -c option was used in the execution of this script";
}
Upvotes: 2
Views: 124
Reputation: 40738
You can use Devel::PL_origargv to get access to to command line parameters that was passed to the perl
interpreter. Example script p.pl
:
use strict;
use warnings;
use Devel::PL_origargv;
my @PL_origargv = Devel::PL_origargv->get;
print Dumper({args => \@PL_origargv});
Then running the script like this for example:
$ perl -MData::Dumper -I. p.pl
$VAR1 = {
'args' => [
'perl',
'-MData::Dumper',
'-I.',
'p.pl'
]
};
Upvotes: 5