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_compatcontrols whether--opt=allowed, , should do. withoutgnu_compat,--opt=gives error.gnu_compat,--opt=give optionopt, 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 );