我的公司使用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 ::龍往往是最頻繁使用的;我認爲要麼是一個可行的選擇,取決於偏好。 –