우리 회사는 명령 행 옵션 파서로 Getopt::Declare
을 사용합니다. 우리의 옵션 처리 블록의 구조는 정기적으로 다음과 같이 :Getopt :: Declare 대 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);
... 나는 대부분의 문서처럼 HEREDOCS를 사용하여 조금 간단하게 만들려고 사용
#!/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
나는 이것이 훨씬 더 읽기 쉽다고 생각하지만, 어떤 이유에서인지 내 주장을 인식하지 못합니다. 것은, Getopt와
사람이 성공적으로을 사용하고있다 HEREDOCS ::를 선언 :
Error: unrecognizable argument ('--client') Error: unrecognizable argument ('154') Error: unrecognizable argument ('--clicks') Error: unrecognizable argument ('2')
그래서 내가 두 quesitons가 추측 :
perl test.pl --client 5 --clicks 2
나는 알 수없는 인수를 얻을?
Getopt :: Declare은 여전히 옵션 파서에 대한 합리적인 옵션입니까? 원래 버전 것은, Getopt 같은 다른 모듈 ::
것은, Getopt :: 선언하고 것은, Getopt가 :: 긴 가장 많이 사용하는 경향이; 내가 선호하는 것에 따라 어느 쪽이든이 실행 가능한 선택이라고 말하고 싶습니다. –