【发布时间】:2014-07-02 22:51:28
【问题描述】:
我正在尝试设置 Getopt::Long 来处理来自配置脚本的参数。
这是我的开胃菜;
#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Long;
my $config_file = '';
GetOptions (
'config|c=s' => \$config_file,
'add|a' => \&add_server,
'del|d' => \&del_server,
);
sub add_server {
print "$config_file\n";
}
sub del_server {
# Left blank for now.
}
奇怪的是,当我用这样的东西运行我的脚本时,我遇到了一个问题,
./config.pl -a -c config.xml
它不会打印-c 选项,但如果我这样运行它,
./config.pl -c config.xml -a
它按原样工作。
我想我明白原因了,这与订单执行有关吧?
问题是我该如何解决?我应该将 Getopt::Long 与 @ARGV 结合使用吗?
最终,我试图让命令行参数传递到我正在调用的子例程中。所以如果-a or --add 我希望-c or --config 的选项在被调用时传递到子程序中。
有什么想法吗?
【问题讨论】:
标签: perl config subroutine getopt-long