chidori has asked for the wisdom of the Perl Monks concerning the following question:

I am using string "readonly" in GetOptions . When i run the script, It looks like its not necessary that i have to give the full name of the string used as option. Lets say i am running the script like this "./script -r" --> this also seems to point to "readonly" Is there anyway , we can avoid this behaviour. I am planning to use few other strings for options in script. Please help me out.
  • Comment on how to get the exact option string in Getopt::Long module

Replies are listed 'Best First'.
Re: how to get the exact option string in Getopt::Long module
by toolic (Bishop) on Nov 21, 2013 at 17:44 UTC
    This is described in the POD: Configuring Getopt::Long. Use no_auto_abbrev:
    use warnings; use strict; use Getopt::Long qw(:config no_auto_abbrev); my %opt; GetOptions(\%opt, qw(readonly)) or die;
Re: how to get the exact option string in Getopt::Long module
by davido (Cardinal) on Nov 21, 2013 at 18:01 UTC

    What is your concern? Is the problem that you might have an option "readonly", and another option "runonly", and you are worried that "--r" will be ambiguous from within the application? Or are you concerned that people might grow accustomed to using --r only to later find things break once you've added runonly? If the concern is the former, you needn't worry; Getopt::Long's POD has this to say:

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

    GetOptions ('length|height=f' => \$length, "head" => \$head);

    This call will allow --l and --L for the length option, but requires a least --hea and --hei for the head and height options.

    So the first possible issue is unfounded, and documented in the module's POD (which the author spent time writing with the hope that you, the user, would read).

    The second possible issue is a social one; the concern that people will get in the habit of using the abbreviations, only to have them become invalidated by the addition of options that push uniqueness further along in the option's string. And for that, the POD is also helpful, by documenting the auto_abbrev configuration setting.


    Dave

      Thanks , Getopt::Long's POD link really helped. I didnt know that auto_abbrev existed :)