Skip Menu |

This queue is for tickets about the Getopt-Long CPAN distribution.

Report information
The Basics
Id: 130639
Status: rejected
Priority: 0/
Queue: Getopt-Long

People
Owner: jv [...] cpan.org
Requestors: violapiratejunky [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: no_pass_through allows extra args
The no_pass_through (default) doesn't allow extra options, but does allow extra arguments: use strict; use warnings; use Getopt::Long qw(:config no_pass_through); GetOptions ("length=i" => \my $length) or die 'error'; print "Length: $length\n"; If you do: perl getopt.pl --length 5 extra_arg You get: Length: 5 Even though extra_arg is passed and length only accepts one value. However, if we do: perl getopt.pl --length 5 --extra_arg Then you get: Unknown option: extra_arg error at getopt.pl line 5. It seems like the first case to be consistent should maybe give an error like: Unknown argument: extra_arg error at getopt.pl line 5
GetOptions parses options and their arguments (e.g. --length 5) and leaves everything else in @ARGV for the program to process. If you do not want 'everything else', just check for @ARGV being zero after the call to GetOptions.
On Thu Oct 03 02:17:03 2019, JV wrote: Show quoted text
> GetOptions parses options and their arguments (e.g. --length 5) and > leaves everything else in @ARGV for the program to process. > > If you do not want 'everything else', just check for @ARGV being zero > after the call to GetOptions.
Yeah, currently I look at @ARGV. I wanted a way to say no extra options or arguments to avoid typos, but I can continue to check @ARGV if you think that's the right design choice. I would love to see something maybe like no_pass_through_options for the current behavior, and no_pass_through_arguments for no additional arguments. Thanks, though! I appreciate the response.