【问题标题】:First value empty for options with multiple values in Perl Getopt::LongPerl Getopt::Long 中具有多个值的选项的第一个值为空
【发布时间】:2013-05-23 20:41:37
【问题描述】:

有人可以帮我理解为什么会发生这种情况。我正在使用 Perl Getopt::Long 来解析具有多个值的选项,但我得到了一些奇怪的结果。以下代码:

#!/usr/bin/perl
use warnings;
use strict;
use Getopt::Long;

my @b_in = "";
GetOptions( 'b=s{,}'  => \@b_in );
my $blen = @b_in;

print "Length of b args: $blen\n";
print "List of b args: $b_in[0], $b_in[1] and $b_in[2]\n";
print "The first b: $b_in[0]\n";

产生这个输出:

$ ./optl.pl -b b_abr c_arg
Length of b args: 3
List of b args: , b_abr and c_arg
The first b: 

为什么参数列表中的第一个参数是空的?

【问题讨论】:

    标签: perl getopt-long


    【解决方案1】:

    因为您使用"" 而不是() 对其进行了初始化。选项被附加到已经存在的元素上。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-19
      相关资源
      最近更新 更多