对于我正在编写的perl脚本,可能会提供很多(〜50)的命令行选项。他们中的大多数是可选的,所以通话只会提供一些选项。如何在Perl中使用Getopt时对参数进行分组?
我正在使用Getopt::Long
,但它不允许我多次使用GetOptions
。因此,我必须在一个GetOptions
调用中使用所有的命令行选项。
在使用GetOptions
时是否有一些很好的方法将选项分组?
$ cat test.pl
use strict;
use warnings;
use Getopt::Long;
my ($a, $b, $c, $d);
GetOptions ('a=s' => \$a, 'b=s' => \$b);
GetOptions ('c=s' => \$c, 'd=s' => \$d);
print "a = $a\nb = $b\nc = $c\nd = $d\n";
$ perl test.pl -a=AA -b=BB -c=CC -d=DD
Unknown option: c
Unknown option: d
Use of uninitialized value in concatenation (.) or string at test.pl line 10.
Use of uninitialized value in concatenation (.) or string at test.pl line 10.
a = AA
b = BB
c =
d =
$
正如我在问题中提到的,我有大约50个,如果他们没有分组,很难跟踪他们。 – Lazer 2010-11-12 10:19:18
@Lazer,那么你将不得不更好地解释“分组”的含义。 GetOptions不关心他们列出的顺序;以任何对你有意义的顺序列出它们。 – cjm 2010-11-12 10:27:14