atoomic / perl-TimeDate

time & date parsing and formatting perl library
http://search.cpan.org/dist/TimeDate/
1 stars 4 forks source link

Not able to restrict the number of arguments for an option with GetOptions in Getopt::Long [rt.cpan.org #72560] #8

Open atoomic opened 4 years ago

atoomic commented 4 years ago

Migrated from rt.cpan.org#72560 (status was 'new')

Requestors:

From svgkraju@yahoo.com on 2011-11-20 08:20:24 :

   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.

From svgkraju@yahoo.com on 2011-11-20 08:30:21 :

Raised this bug against wrong module. Please cancel this ticket.

On Sun Nov 20 03:20:24 2011, svgkraju wrote:
>    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.