6

I am using the Getopt::Long module to process command line arguments.

The typical behavior of this module is we could pass -f instead of full name of the variable --file. At the same time if I have another command line variable --find, and if I supply only -f at the command prompt, it would return with an error:

Option f is ambiguous (file, find).

I was wondering how can we curb such ambiguous usage?

Thanks in advance.

Sinan Ünür
  • 116,958
  • 15
  • 196
  • 339
Gentle
  • 197
  • 8
  • 2
    @downvoter : This question is useful and clear. – Zaid Jun 28 '12 at 11:49
  • 2
    Upvoters: the question [shows no research effort](http://stackoverflow.com/questions/how-to-ask), it can be answered by reading the documentation alone. – daxim Jun 28 '12 at 13:26

2 Answers2

11

Have a look at the Getopt::Long documentation:

auto_abbrev

Allow option names to be abbreviated to uniqueness. Default is enabled unless environment variable POSIXLY_CORRECT has been set, in which case auto_abbrev is disabled.


Example:

use strict;
use warnings;
use Getopt::Long qw(:config no_auto_abbrev);

my ( $file, $fish );

GetOptions( "file=s" => \$file, "fish=s" => \$fish );

And the tests:

$ perl test.pl -fi 24
Unknown option: fi

$ perl test.pl -fis 24
Unknown option: fis
Zaid
  • 36,680
  • 16
  • 86
  • 155
3

If you want to turn this auto abbreviation feature off you'll have to configure Getopt::Long using

use Getopt::Long qw(:config no_auto_abbrev) ;
dgw
  • 13,418
  • 11
  • 56
  • 54