Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: getopts and -?

by Anonymous Monk
on May 10, 2011 at 01:19 UTC ( #903870=note: print w/ replies, xml ) Need Help??


in reply to getopts and -?

getopts('oif:', \%opts); # options as above. Values in %opts
no strict 'refs'; warn local ${"opt_?"} = 6;
use Getopt::Long; GetOptions( q!help|h|?! => \$help );
$ perl -MGetopt::Long -e " my $help; GetOptions( q!help|h|?! => \$help + ); warn $help; " -- --help 1 at -e line 1. $ perl -MGetopt::Long -e " my $help; GetOptions( q!help|h|?! => \$help + ); warn $help; " -- -h 1 at -e line 1. $ perl -MGetopt::Long -e " my $help; GetOptions( q!help|h|?! => \$help + ); warn $help; " -- -? 1 at -e line 1. $ perl -MGetopt::Long -e " my $help; GetOptions( q!help|h|?! => \$help + ); warn $help; " -- -f Unknown option: f Warning: something's wrong at -e line 1.


Comment on Re: getopts and -?
Select or Download Code
Re^2: getopts and -?
by viffer (Sexton) on May 10, 2011 at 02:35 UTC
    Thanks for both your help.

    I have now got it working aside of one issue.

    our ( $opt_d,$opt_h,$opt_l,$opt_L,$opt_i,$opt_o,$opt_P,$opt_p,$opt_q,$ +opt_r,$opt_v,$opt_c,$opt_z ); # 'L' =>\$opt_L, # 'p' =>\$opt_p, GetOptions ( 'd' =>\$opt_d, 'h' =>\$opt_h, 'l' =>\$opt_l, 'i' =>\$opt_i, 'o:s' =>\$opt_o, 'P:s' =>\$opt_P, 'q' =>\$opt_q, 'r' =>\$opt_r, 'v:s' =>\$opt_v, 'c' =>\$opt_c, 'help|?!' =>\$opt_z, );
    If I include both upper and lower case options L and P I end up getting the error message
    'Duplicate specification "L" for option "l"'

    Is there a way to parse both upper and lower case characters for the same letter?

    Appreciate your time and help.
      Oops..posted my version prior to reading your responses (honest i had got there off my own accord!) but like your versions, you both have "L & l" and "P & p" which getoptions doesn't seem to like, thinking they are duplicates.
        Case and abbreviations

        Without additional configuration, GetOptions() will ignore the case of option names, and allow the options to be abbreviated to uniqueness.

        Just wondering if anyone knows what "additional configuration" is required?

        Thank you, I should learn in future to take more time before i ask a question. You were typing a response at the same time as i was asking the question! :)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (9)
As of 2013-05-25 19:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best material for plates (tableware) is:









    Results (520 votes), past polls