Subject: | Not able to restrict the number of arguments for an option with GetOptions in Getopt::Long |
use strict;
use warnings;
use Getopt::Long;
my @letters;
my @words;
GetOptions(
"letters=s{2}" => \@letters,
"words=s{,}" => \@words
);
print "Letters: " . join(", ", @letters) . "\n";
print "Words: " . join(", ", @words) . "\n";
When I run this program I get the output as follows:
perl getopts.pl --letters a --words he she it
Letters: a, --words
Words:
--words is read as part of --letters arguments itself. I expect
GetOptions to throw error message in this scenario. How to get this done.
FYI....
Z:\examples\perl>perl -v
This is perl 5, version 14, subversion 2 (v5.14.2) built for
MSWin32-x86-multi-t
hread
(with 1 registered patch, see perl -V for more detail)
Copyright 1987-2011, Larry Wall
Binary build 1402 [295342] provided by ActiveState
http://www.ActiveState.com
Built Oct 7 2011 15:49:44
Perl may be copied only under the terms of either the Artistic License
or the
GNU General Public License, which may be found in the Perl 5 source kit.
Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl". If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.