Skip Menu |

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

Report information
The Basics
Id: 125370
Status: resolved
Priority: 0/
Queue: Getopt-Long

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

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



Subject: Impossible to have option "-="
There doesn't seem to be any way to use Getopt::Long if it is necessary to parse a single-letter "=" option. GetOptions( "=" => sub{...} # Error in spec: "CODE{...}" "=|alias" => sub {...} # Error in spec "=|alias" "\\=" => \$var, # Error in spec: "SCALAR(...)" '<>' => sub{ ... } # Never called; parse fails I tried using In case you are wondering why I want to do this, I'm writing a wrapper which passes through arguments to the a2ps(1) command, which accepts things like -=blahblah.
Seems you've hit the limit of sanity... I'd really not know what to do with this.
Subject: Impossible to have option "-=" (PATCH)
On Mon May 21 13:46:04 2018, JV wrote: Show quoted text
> Seems you've hit the limit of sanity...
Maybe you're right :-| I was just trying to meet a pre-existing ineterface. In case you want to consider it, attached is a patch which allows backslash escapes for single-character option names. In particular "\\==s" => \$optequalval works. Note: I only tested this informally using perl v5.26.1, but I tried not to use anything which might not work in an older perl. I have not downloaded the package with test suite. -Jim
Subject: patchfile.txt
--- Long.pm 2018-05-21 23:25:39.134688537 +0000 +++ Long.pm.NEW 2018-05-22 00:18:48.057523155 +0000 @@ -4,7 +4,7 @@ # Author : Johan Vromans # Created On : Tue Sep 11 15:00:12 1990 # Last Modified By: Johan Vromans -# Last Modified On: Thu Jun 9 14:50:37 2016 +# Last Modified On: Thu Jun 9 14:50:37 2016 **HACKED jima 5/21/18** # Update Count : 1699 # Status : Released @@ -795,6 +795,8 @@ ). "]"; } +my $optname_re = qr/(?:\w+[-\w]*|\?|\\.)/; # \c means c for any c + # Parse an option specification and fill the tables. sub ParseOptionSpec ($$) { my ($opt, $opctl) = @_; @@ -802,12 +804,10 @@ # Match option spec. if ( $opt !~ m;^ ( - # Option name - (?: \w+[-\w]* ) - # Alias names, or "?" - (?: \| (?: \? | \w[-\w]* ) )* - # Aliases - (?: \| (?: [^-|!+=:][^|!+=:]* )? )* + # Primary Option name + ${optname_re} + # Alias names + (?: \| ${optname_re} )* )? ( # Either modifiers ... @@ -836,8 +836,10 @@ my @names; if ( defined $names ) { - @names = split (/\|/, $names); - $orig = $names[0]; + local $_ = "|$names"; + @names = (/\G\|(${optname_re})/g) or die; + s/^\\// for @names; # get rid of \ escape + $orig = $names[0]; } else { @names = ('');
Interesting... But it can be done easier :) . In 2.39 I implemented "Other characters that can't appear in Perl identifiers are also supported as aliases". This works for anything but |!:=+ . I can lift this restriction so that the first (or only) character may be anything (except newline). Your use case becomes: "user-option|==s"
Subject: poweraliases.patch
--- lib/Getopt/Long.pm~ 2018-05-22 13:54:04.607803985 +0200 +++ lib/Getopt/Long.pm 2018-05-22 14:07:42.221485187 +0200 @@ -805,10 +805,8 @@ ( # Option name (?: \w+[-\w]* ) - # Alias names, or "?" - (?: \| (?: \? | \w[-\w]* ) )* # Aliases - (?: \| (?: [^-|!+=:][^|!+=:]* )? )* + (?: \| (?: . [^|!+=:]* )? )* )? ( # Either modifiers ... @@ -2738,8 +2736,10 @@ use Getopt::Long; GetOptions ("help|?"); # -help and -? will both set $opt_help -Other characters that can't appear in Perl identifiers are also supported -as aliases with Getopt::Long of at least version 2.39. +Other characters that can't appear in Perl identifiers are also +supported in aliases with Getopt::Long of at version 2.39. Note that +the characters C<!>, C<|>, C<+>, C<=>, and C<:> can only appear as the +first (or only) character of an alias. As of version 2.32 Getopt::Long provides auto-help, a quick and easy way to add the options --help and -? to your program, and handle them.