could someone help me understanding why the bellow is happening. I am using Perl Getopt::Long to parse options with multiple values, but I am geting some strange results. The following code:
#!/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";
produces this output:
$ ./optl.pl -b b_abr c_arg
Length of b args: 3
List of b args: , b_abr and c_arg
The first b:
Why the first argument in the argument list is empty?
Because you initialized it with ""
instead of ()
. The options got appended to the element that was already there.