in reply to Enforce single hyphen for single character options in Getopt::Long

There is something up with the way the arguments are processed. The prefix symbol appears to apply escapes whereas the _pattern suffixed symbols do not.

Alongside the equal sign not being documented as mentioned recently in Solved- Getopt::Long- Trying to specify "prefix" configuration option produces error, apparantly you can also supply a regex.

With the proviso the qr is inline, a quoted regex pattern can be supplied to pattern_prefix that appears to do what we need, without the need to import long_pattern_prefix at all.

Though this is fairly simple case in that it is only distinguishing between single or double option introduction characters. On one system, so perhaps there is scope for further regex formulations in combination. It would be easy to expect that there is a kind of default fallback hieararchy to these for varying levels of complexity requirements. Documented intention would be even easier

use strict; use warnings; use Getopt::Long ( qw( :config posix_default gnu_compat bundling no_auto_abbrev no_ignore_case passthrough ), 'prefix_pattern=' . qr/((?<=)(?=--\w{2,})--)|((?<=)(?=-\w+)-)/ ); my $column=1; GetOptions( 'column|c=i' => \$column, # 'c=i'=> \$column, ) or die; # with passthrough, tell the user their option wasnt applied # print map "[$_]", @ARGV, "\n"; print "\$column is $column\n"; die if $column < 1; __END__ $ ~/Desktop/gol.pl --column=2 $column is 2 $ ~/Desktop/gol.pl --column 2 $column is 2 $ ~/Desktop/gol.pl --c=2 $column is 1 $ ~/Desktop/gol.pl --c 2 $column is 1 #'column|c=i' => \$column, $ ~/Desktop/gol.pl -c=2 $column is 1 # 'column=i' => \$column, # 'c=i'=> \$column, $ ~/Desktop/gol.pl -c=2 Value "=2" invalid for option c (number expected) Died at /c/Users/archimediiiica/Desktop/gol.pl line 53. $ ~/Desktop/gol.pl -c2 $column is 2 #passthrough $ ~/Desktop/gol.pl --c 2 [--c][2][ ]$column is 1 #passthrough $ ~/Desktop/gol.pl --c=2 [--c=2][ ]$column is 1

The difference between the alternation in the GetOptions call, is the Warning when -c=2 is not generated

Importing passthrough allows to see that this is still preferable to my earlier @ARGV processing solution, as it keeps the failed option and value pair together, so it could be nice to the user to let them know some option or other was not applied, else they may get unexpected results from default args.


Dont Coyote