对于我正在编写的 perl 脚本,可以提供很多(约 50 个)命令行选项。它们中的大多数是可选的,因此调用将只提供一些选项。
我正在使用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 =
$