我的公司使用Getopt::Declare
作为它的命令行选项解析器。我们的选择处理块的结构通常是这样的:Getopt :: Declare vs Getopt :: Long
Readonly my $ARGS => Getopt::Declare->new(
join("\n",
"[strict]",
"--engineacct <num:i>\tEngineaccount [required]",
"--outfile <outfile:of>\tOutput file [required]",
"--clicks <N:i>\tselect keywords with more than N clicks [required]",
"--infile <infile:if>\tInput file [required]",
"--pretend\tThis option not yet implemented. "
. "If specified, the script will not execute.",
"[ mutex: --clicks --infile ]",
)
) || exit(1);
这是很多来看看......我尝试用here文档最喜欢的文件,使之成为简单一些用途:
#!/usr/bin/perl
use strict;
use warnings FATAL => 'all';
use Readonly;
Readonly my $ARGS => Getopt::Declare->new(<<'EOPARAM');
[strict]
--client <client:i> client number [required]
--clicks <clicks:i> click threshold (must be > 5)
EOPARAM
虽然我觉得这样更容易阅读,但出于某种原因,它不会识别我的任何论点。
perl test.pl --client 5 --clicks 2
我得到无法识别的参数:
Error: unrecognizable argument ('--client')
Error: unrecognizable argument ('154')
Error: unrecognizable argument ('--clicks')
Error: unrecognizable argument ('2')
所以我想我有两个quesitons:
已成功用于人用here文档Getopt的::声明?
是Getopt :: Declare仍然是一个选项解析器的合理选项?相对于其他模块,如的Getopt ::龙
的Getopt ::声明和的Getopt ::龙往往是最频繁使用的;我认为要么是一个可行的选择,取决于偏好。 –