perl - In newer Getopt::Long How do I set default optional values -


in perl's getopt::long version 2.39 use

use getopt::long qw( :config gnu_getopt ); getoptions(    \my %opts,     "codon-view|c:20",    # optional value, default 20    "consensus|c:50",     ... ) 

to indicate if use -c default value 20 put in %optsunder key codon-view when -c given no explicit value there. on other hand -c or --codon-view not supplied, no value in hash table stored in %opts.

in 2.48 no longer works , don't see in getopt::long's documentation

$ perl -e'    use getopt::long qw( :config gnu_getopt );    $getopt::long::version;    getoptions(\my %opts, "codon-view|c:20");    $opts{"codon-view"} // "[undef]" ' -- -c 2.39 20  $ perl -e'    use getopt::long qw( :config gnu_getopt );    $getopt::long::version;    getoptions(\my %opts, "codon-view|c:20");    $opts{"codon-view"} // "[undef]" ' -- -c 2.48 [undef] 

how can achieve old behavior?

help!

this change introduced in 2.48.

$ perl -e'    use getopt::long qw( :config gnu_getopt );    $getopt::long::version;    getoptions(\my %opts, "codon-view|c:20");    $opts{"codon-view"} // "[undef]" ' -- -c 2.47 20  $ perl -e'    use getopt::long qw( :config gnu_getopt );    $getopt::long::version;    getoptions(\my %opts, "codon-view|c:20");    $opts{"codon-view"} // "[undef]" ' -- -c 2.48 [undef] 

i'm not sure, think done unintentionally, filed bug report.


use getopt::long qw( :config gnu_getopt ); 

is short for

use getopt::long qw( :config gnu_compat bundling permute no_getopt_compat ); 

how invested in using gnu_compat?

$ perl -e'    use getopt::long qw( :config gnu_getopt );    $getopt::long::version;    getoptions(\my %opts, "codon-view|c:20");    $opts{"codon-view"} // "[undef]" ' -- -c 2.48 [undef]  $ perl -e'    use getopt::long qw( :config gnu_compat bundling permute no_getopt_compat );    $getopt::long::version;    getoptions(\my %opts, "codon-view|c:20");    $opts{"codon-view"} // "[undef]" ' -- -c 2.48 [undef]  $ perl -e'    use getopt::long qw( :config bundling permute no_getopt_compat );    $getopt::long::version;    getoptions(\my %opts, "codon-view|c:20");    $opts{"codon-view"} // "[undef]" ' -- -c 2.48 20 

gnu_compat controls whether --opt= allowed, , should do. without gnu_compat, --opt= gives error. gnu_compat, --opt= give option opt , empty value. way gnu getopt_long() it.

so if you're ok --codon-view= assigning 0 $opts{"codon-view"}, use

use getopt::long qw( :config bundling permute no_getopt_compat ); 

instead of

use getopt::long qw( :config gnu_getopt ); 

Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

python 3.x - PyQt5 - Signal : pyqtSignal no method connect -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)