Using Perl Getopt :: Long, how can I prevent a module from trying to match ambiguous option names?

I use a module Getopt::Longto process command line arguments.

The typical behavior of this module is that we can pass -finstead of the full name of the variable --file. At the same time, if I have another command line variable --find, and if I put it only -fon the command line, it will return with an error:

Option f is ambiguous (file, find).

I was wondering how we can curb such ambiguous use?

Thanks in advance.

+5
source share
2 answers

See the Getopt::Longdocumentation:

auto_abbrev

. POSIXLY_CORRECT, case auto_abbrev .


:

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

my ( $file, $fish );

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

:

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

$ perl test.pl -fis 24
Unknown option: fis
+9

, Getopt:: Long

use Getopt::Long qw(:config no_auto_abbrev) ;
+3

All Articles