Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Force Getopt::Long to Require ONLY Equals Sign Between Option Name and Value

by haukex (Chancellor)
on Oct 19, 2019 at 08:50 UTC ( #11107686=note: print w/replies, xml ) Need Help??


in reply to Force Getopt::Long to Require ONLY Equals Sign Between Option Name and Value

I also don't see a way to do that via configuration options at the moment. But @ARGV is just an array of strings, so you could just do e.g. "s/^-ot\K$/=/ for @ARGV;" before the GetOptions call:

use warnings; use strict; use Getopt::Long qw/ GetOptionsFromArray /; use Test::More tests => 6; my @argv1 = qw/ -ot=123 arg1 arg2 /; s/^-ot\K$/=/ for @argv1; is_deeply \@argv1, ["-ot=123", "arg1", "arg2"]; GetOptionsFromArray(\@argv1, \my %opts1, "ot:s") or die; is_deeply \%opts1, { ot => 123 }; is_deeply \@argv1, ["arg1", "arg2"]; my @argv2 = qw/ -ot arg1 arg2 /; s/^-ot\K$/=/ for @argv2; is_deeply \@argv2, ["-ot=", "arg1", "arg2"]; GetOptionsFromArray(\@argv2, \my %opts2, "ot:s") or die; is_deeply \%opts2, { ot => "" }; is_deeply \@argv2, ["arg1", "arg2"];

Update: Switched from Data::Dump to Test::More.

Replies are listed 'Best First'.
Re^2: Force Getopt::Long to Require ONLY Equals Sign Between Option Name and Value
by roho (Canon) on Oct 19, 2019 at 20:53 UTC
    Thank you all for your replies. I am going with the suggestion from haukex. That approach meets my current need and keeps me moving forward.
    I will ask the author of Getopt::Long if a configuration option can be added to the module to accomplish this in the future. Thanks again.

    "It's not how hard you work, it's how much you get done."

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11107686]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (3)
As of 2019-11-16 02:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Strict and warnings: which comes first?



    Results (85 votes). Check out past polls.

    Notices?