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

I am using Getopt::Long::GetOptions and want to have my script die if an unknown option is passed. I tried using Getopt::Long qw(:config require_order) which from what I can tell in the docs should have worked. Any suggestions are as always appreciated. SNIPPET:
use Getopt::Long qw(:config require_order); Getopt::Long::GetOptions( 'domain=s' => \$domain, 'help!' => \$help ); print "DOMAIN IS $domain\n";

Replies are listed 'Best First'.
Re: How to die if Getopt::Long::GetOptions returns "Unknown option"
by Fletch (Bishop) on Feb 03, 2004 at 16:54 UTC

    perldoc Getopt::Long

    Return values and Errors
    ... GetOptions returns true to indicate success. It returns false when the function detected one or more errors during option parsing. These errors are signalled using warn() and can be trapped with $SIG{__WARN__}.
    my $ret = GetOptions( ... ); die "usage: $0 [options]\n" unless $ret;