我正在尝试将getoptfromGetopt::Std用于多个参数。我有getopt('s:il');我想s成为强制搜索词、i可选整数和l可选字母的地方。当我使用全部 3 个时,这是有效的,但是如果我添加'-s search -i -l g'到我的命令行,我会-l在我的变量中获得结果 for i,而不是 Perl 将其识别-i为空白并'g'作为l. 有没有解决的办法?我需要使用备用 getopt(s) 命令吗?
1 回答
            2        
        
		
使用getopts函数代替getopt:
use warnings;
use strict;
use Getopt::Std;
my %opts;
getopts('s:il', \%opts);
use Data::Dumper;
$Data::Dumper::Sortkeys=1;
print Dumper(\%opts);
__END__
my_script.pl -s foo -i -l
$VAR1 = {
          'i' => 1,
          'l' => 1,
          's' => 'foo'
        };
于 2013-05-15T21:17:53.307   回答