2013-11-27 3 views
3

우리 회사는 명령 행 옵션 파서로 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와

사람이 성공적으로
  1. 을 사용하고있다 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 
    

    나는 알 수없는 인수를 얻을?

  2. Getopt :: Declare은 여전히 ​​옵션 파서에 대한 합리적인 옵션입니까? 원래 버전 것은, Getopt 같은 다른 모듈 ::

+0

것은, Getopt :: 선언하고 것은, Getopt가 :: 긴 가장 많이 사용하는 경향이; 내가 선호하는 것에 따라 어느 쪽이든이 실행 가능한 선택이라고 말하고 싶습니다. –

답변

5

긴 반대로, 당신의 캐릭터는 select keywords with more than N clicks [required] 다음, 탭 다음 --clicks <N:i>로 구성되어 있습니다.

수정 된 버전에는 문자열 대신 탭이 있습니다.

<<'EOPARAM' 및 ""대신 <<"EOPARAM" 및 "\t"을 사용하십시오.

>type x.pl 
use Getopt::Declare; 
Getopt::Declare->new(<<'EOPARAM'); 
    [strict] 
    --client <client:i> client number [required] 
    --clicks <clicks:i> click threshold (must be > 5) 
EOPARAM 

>perl x.pl --client 5 --clicks 2 
Error: unrecognizable argument ('--client') 
Error: unrecognizable argument ('5') 
Error: unrecognizable argument ('--clicks') 
Error: unrecognizable argument ('2') 

(try 'x.pl -help' for more information) 

>type x.pl 
use Getopt::Declare; 
Getopt::Declare->new(<<'EOPARAM'); 
    [strict] 
    --client <client:i>\tclient number [required] 
    --clicks <clicks:i>\tclick threshold (must be > 5) 
EOPARAM 

>perl x.pl --client 5 --clicks 2 
Error: unrecognizable argument ('--client') 
Error: unrecognizable argument ('5') 
Error: unrecognizable argument ('--clicks') 
Error: unrecognizable argument ('2') 

(try 'x.pl -help' for more information) 

>type x.pl 
use Getopt::Declare; 
Getopt::Declare->new(<<"EOPARAM"); 
    [strict] 
    --client <client:i>\tclient number [required] 
    --clicks <clicks:i>\tclick threshold (must be > 5) 
EOPARAM 

>perl x.pl --client 5 --clicks 2 

> 
+0

공백이 제거 된 경우에도 여전히 인식 할 수 없습니다. –

+0

그래, 그걸 알아 냈어. 업데이트 됨. – ikegami

+0

왜 탭이 필요한지 혼란 스럽지만 도움을 주셔서 감사합니다. –