When I started, I had something like:
my ($option1, $option2, $option3, $option4, @option5);
my $result = GetOptions('option1=s' => \$option1,
'option2=i' => \$option2,
'option3=s' => \$option3,
'option4=s' => \$option4,
'option5=i{,}' => \@option5);
I wanted to change it to store the options in a hash since I had several options but got confused with the option that takes multiple values using a repeat specifier. The reason was stated in the documentation that "The destination for the option must be an array or array reference." What I didn't realize is that I needed to use this syntax "Alternatively, you can specify that the option can have multiple values by adding a "@", and pass a scalar reference as the destination" since my destination was now an uninitialized hash entry.
I ended up with this:
my %options;
my $result = GetOptions(\%options, 'option1=s',
'option2=i',
'option3=s',
'option4=s',
'option5=i@{,}');
No comments:
Post a Comment