Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
有没有一种方法可以识别哪些特定于perl的选项被传递给脚本?_Perl - Fatal编程技术网

有没有一种方法可以识别哪些特定于perl的选项被传递给脚本?

有没有一种方法可以识别哪些特定于perl的选项被传递给脚本?,perl,Perl,我知道脚本可以检索通过ARGV传递给它的所有命令行参数,即: # test.pl print "$ARGV[0]\n"; print "$ARGV[1]\n"; print "$ARGV[2]\n"; ## perl ./test.pl one two three one two three 在上面的示例中,传递给test.pl脚本的命令行参数是“一”、“二”和“三” 现在,假设我运行以下命令: ## perl -d:DumpTr

我知道脚本可以检索通过ARGV传递给它的所有命令行参数,即:

# test.pl

print "$ARGV[0]\n";
print "$ARGV[1]\n";
print "$ARGV[2]\n";

## perl ./test.pl one two three
one
two
three
在上面的示例中,传递给
test.pl
脚本的命令行参数是“一”、“二”和“三”

现在,假设我运行以下命令:

## perl -d:DumpTrace test.pl one two three

or

## perl -c test.pl one two three
如何从
test.pl
脚本的操作中判断选项
-c
-d:DumpTrace
已传递给perl解释器

我正在寻找一种方法,可以识别在脚本执行过程中何时将选项传递给perl解释器:

if "-c" was used in the execution of `test.pl` script {
    print "perl -c option was used in the execution of this script";
}
您可以使用来访问传递给
perl
解释器的命令行参数。示例脚本
p.pl

use strict;
use warnings;
use Devel::PL_origargv;
my @PL_origargv = Devel::PL_origargv->get;
print Dumper({args => \@PL_origargv});
然后像这样运行脚本,例如:

$ perl -MData::Dumper -I. p.pl
$VAR1 = {
          'args' => [
                      'perl',
                      '-MData::Dumper',
                      '-I.',
                      'p.pl'
                    ]
        };

即使您可以这样做,
打印
也不会产生任何结果,因为
-c
不会运行脚本(除非您将整个if放入一个BEGIN块)。请参见,这看起来正是我所需要的。唯一的问题是模块
Devel::PL_origargv
没有内置到perl中。这是我必须得到的额外模块。有没有办法绕过这个问题?我不想要求用户必须担心得到这个软件包。是否有一种有效的方法将模块的内容包含在
p.pl
脚本本身中?@KLZY正如toolic所提到的,它是一个XS模块,因此用户需要在机器上编译它才能使用它。但是,您可以尝试使用(例如)将模块编译为可执行文件,然后将该可执行文件分发给您的用户。尽管如此,我相信这要求用户使用与您相同的体系结构和perl版本。@KLZY尽管名称不同,但这可能无法获得“原始”命令行,请参见例如
perl-MDevel::PL\u origargv-le'$0=“lol-cat”;打印Devel::PL\u origargv->get'
。坦率地说,我不明白它的目的:为什么你不能只写一个包装?