Closed p5pRT closed 22 years ago
Wanting to create a utility that takes both long and short options\, I decided to use Getopt::Long to do my option parsing.
Unfortunally\, it looks as if it cannot distinguish between one letter options that differ in case. I looked in the source\, and when there's a one-letter option in upper case\, it's going to make the lower case variant an "alias" for this option. This contradicts the documentation that says:
ignore_case (default: enabled) If enabled\, case is ignored when matching long option names. Single character options will be treated case-sensitive.
Note: disabling "ignore_case" also disables "ignore_case_always".
Only by specifically calling C\<Getopt::Long::Configure 'no_ignore_case'>\, Getopt::Long is able to distinguish between '-e' and '-E'.
I do not know whether the documentation is wrong\, or the source.
(This is Getopt::Long version 2.26_03).
$ cat x.pl #!/opt/bleadperl/bin/perl -w
use strict;
use Getopt::Long;
GetOptions e => sub {print "Found lowercase `e'\n"}\, E => sub {print "Found uppercase `E'\n"};
__END__ $ ./x.pl -E Found uppercase `E' $ ./x.pl -e Found uppercase `E'
Abigail
I think it's a documentation issue. The concept of 'single character option' implies the use of the 'bundling' configuration option. Without bundling\, a single character option is just a long option of one character\, and taken case independent.
% cat t1.pl #!/opt/bleadperl/bin/perl -w use strict; use Getopt::Long qw(:config debug); GetOptions e => sub {print "Found lowercase `e'\n"}\, E => sub {print "Found uppercase `E'\n"};
% perl -w t1.pl
GetOpt::Long 2.2603 ($Revision: 2.47 $) called from package "main".
ARGV: ()
autoabbrev=1\,bundling=0\,getopt_compat=1\,gnu_compat=0\,order=1\,
ignorecase=1\,passthrough=0\,genprefix="(--|-|\+)".
=> link "e" to CODE(0x8163960)
=> link "E" to CODE(0x80fa8b4)
=> $opctl{e} = ARRAY(0x80eace8) [""\,M\,$\,\
There's only one option in this case.
% cat t2.pl #!/opt/bleadperl/bin/perl -w use strict; use Getopt::Long qw(:config debug bundling); GetOptions e => sub {print "Found lowercase `e'\n"}\, E => sub {print "Found uppercase `E'\n"};
% perl -w t2.pl
GetOpt::Long 2.2603 ($Revision: 2.47 $) called from package "main".
ARGV: ()
autoabbrev=1\,bundling=1\,getopt_compat=1\,gnu_compat=0\,order=1\,
ignorecase=1\,passthrough=0\,genprefix="(--|-|\+)".
=> link "e" to CODE(0x8172a34)
=> link "E" to CODE(0x8172b30)
=> $opctl{e} = ARRAY(0x8182df0) [""\,M\,$\,\
Now\, there are two.
Would this be more clear:
ignore_case (default: enabled) If enabled\, case is ignored when matching long option names. If\, however\, bundling is enabled as well\, single character options will be treated case-sensitive.
-- Johan
I think it's a documentation issue. The concept of 'single character option' implies the use of the 'bundling' configuration option. Without bundling\, a single character option is just a long option of one character\, and taken case independent.
% cat t1.pl #!/opt/bleadperl/bin/perl -w use strict; use Getopt::Long qw(:config debug); GetOptions e => sub {print "Found lowercase `e'\n"}\, E => sub {print "Found uppercase `E'\n"};
% perl -w t1.pl
GetOpt::Long 2.2603 ($Revision: 2.47 $) called from package "main".
ARGV: ()
autoabbrev=1\,bundling=0\,getopt_compat=1\,gnu_compat=0\,order=1\,
ignorecase=1\,passthrough=0\,genprefix="(--|-|\+)".
=> link "e" to CODE(0x8163960)
=> link "E" to CODE(0x80fa8b4)
=> $opctl{e} = ARRAY(0x80eace8) [""\,M\,$\,\
There's only one option in this case.
% cat t2.pl #!/opt/bleadperl/bin/perl -w use strict; use Getopt::Long qw(:config debug bundling); GetOptions e => sub {print "Found lowercase `e'\n"}\, E => sub {print "Found uppercase `E'\n"};
% perl -w t2.pl
GetOpt::Long 2.2603 ($Revision: 2.47 $) called from package "main".
ARGV: ()
autoabbrev=1\,bundling=1\,getopt_compat=1\,gnu_compat=0\,order=1\,
ignorecase=1\,passthrough=0\,genprefix="(--|-|\+)".
=> link "e" to CODE(0x8172a34)
=> link "E" to CODE(0x8172b30)
=> $opctl{e} = ARRAY(0x8182df0) [""\,M\,$\,\
Now\, there are two.
Would this be more clear:
ignore_case (default: enabled) If enabled\, case is ignored when matching long option names. If\, however\, bundling is enabled as well\, single character options will be treated case-sensitive.
-- Johan
Yes\, I would think so.
Abigail
@abigail - Status changed from 'open' to 'resolved'
@sciurius - Status changed from 'open' to 'resolved'
Migrated from rt.perl.org#7928 (status was 'resolved')
Searchable as RT7928$