Perl 指定可选参数的正确语法是什么?

Perl 指定可选参数的正确语法是什么?,perl,syntax,Perl,Syntax,我有一个Perl脚本,可以称为 perl mysrc.pl -a=3 -b=4 -c=6 或作为 基本上,(为t提供值)或(为所有a、b和c提供值)。必须至少指定一组值 我该如何用语法表达上述内容 perl mysrc.pl [-a=<value of a>] [-b=<value of b>] [-c=<value of c>] [-t=<value of t>] perl mysrc.pl [-a=]

我有一个Perl脚本,可以称为

perl mysrc.pl -a=3 -b=4 -c=6
或作为

基本上,(为
t
提供值)或(为所有
a
b
c
提供值)
。必须至少指定一组值

我该如何用语法表达上述内容

perl mysrc.pl
     [-a=<value of a>]
     [-b=<value of b>]
     [-c=<value of c>]
     [-t=<value of t>]
perl mysrc.pl
[-a=]
[-b=]
[-c=]
[-t=]

这意味着所有参数都是可选的,但事实并非如此。编写mysrc.pl语法的正确方法是什么?

您指的只是帮助文本?在这种情况下,您可以执行Subversion所做的操作,例如:

$ svn help merge
merge: Apply the differences between two sources to a working copy path.
usage: 1. merge sourceURL1[@N] sourceURL2[@M] [WCPATH]
       2. merge sourceWCPATH1@N sourceWCPATH2@M [WCPATH]
       3. merge [-c M[,N...] | -r N:M ...] SOURCE[@REV] [WCPATH]
我可能会使用:

mycmd [ -t=tval | -a=aval -b=bval -c=cval ] ...
其中,“…”表示任何其他选项,或文件名,或根本不表示任何内容。如果其中一个集合是必需的,我可能会使用大括号“
{}
”而不是方括号“
[]
”。方括号通常表示“可选”。

两个选项:使用“|”作为“或”符号,使用非方括号进行分组以避免“可选”上下文,或在多行上列出相互竞争的用法

perl mysrc.pl {-a=<value of a> -b=<value of b> -c=<value of c>|-t=<value of t>}

perl mysrc.pl UseCaseOneOptions|UseCaseTwoOptions
     UseCaseOneOptions: -a=<value of a> -b=<value of b> -c=<value of c>
     UseCaseTwoOptions: -t=<value of t>
perl mysrc.pl{-a=-b=-c=|-t=}
perl mysrc.pl UseCaseOneOptions | UseCaseTwoOptions
UseCaseOne选项:-a=-b=-c=
UseCaseToworptions:-t=
对于非常复杂的选项集(想想CVS),做CVS做的事情(目前没有xterm,因此下面是一个来自内存的粗略近似值)——也就是说,通用“帮助”消息只列出所有可能的用例,要获得关于每个用例的选项集的帮助,可以发出每个用例的帮助命令

$ cvs --help
  Usage: cvs <command> <per-command-options>
  Please type "cvs command --help" to get help on specific command's options
  Commands are: 
      cvs add
      cvs commmit
      cvs remove
      ...

$ cvs checkout --help
  Usage: cvs checkout [-p] [-A] [-m message] [-M message_file] file_path
      -m message:          check-in comment
      -M file:             read check-in comment from this file
      -p:                  non-sticky checkout. Print the file to STDOUT.

$ cvs diff --help
  Usage: cvs diff [-r VER1] [-r VER2] [-w] file_path
       -w:                 Ignore whitespace
$cvs——帮助
用法:cvs
请键入“cvs命令--help”以获取有关特定命令选项的帮助
命令包括:
cvs添加
cvs通信
cvs移除
...
$cvs签出-帮助
用法:cvs签出[-p][-A][-m消息][-m消息文件]文件路径
-m消息:签入注释
-M文件:从此文件读取签入注释
-p:无粘性结帐。将文件打印到标准输出。
$cvs diff--帮助
用法:cvs diff[-r VER1][-r VER2][-w]文件路径
-w:忽略空白
$ cvs --help
  Usage: cvs <command> <per-command-options>
  Please type "cvs command --help" to get help on specific command's options
  Commands are: 
      cvs add
      cvs commmit
      cvs remove
      ...

$ cvs checkout --help
  Usage: cvs checkout [-p] [-A] [-m message] [-M message_file] file_path
      -m message:          check-in comment
      -M file:             read check-in comment from this file
      -p:                  non-sticky checkout. Print the file to STDOUT.

$ cvs diff --help
  Usage: cvs diff [-r VER1] [-r VER2] [-w] file_path
       -w:                 Ignore whitespace