【发布时间】:2011-05-08 23:43:06
【问题描述】:
对于我正在编写的 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 =
$
【问题讨论】:
标签: perl command-line command-line-arguments getopt