in reply to Re: Requiring option values in Getopt::Long
in thread Requiring option values in Getopt::Long
Why the redundant error error message? A cleaner version was previously suggested to you.
GetOptions( 'test=s' => \$option_test ) or exit(1); defined($option_test) or die("Missing argument -t");
At the very least, remove the line number from the error message. It's useless clutter.
GetOptions( 'test=s' => \$option_test ) or die("Invalid command-line option\n"); defined($option_test) or die("Missing argument -t\nInvalid command-line option\n");
However, I suggest that you display a useful error message instead:
use File::Basename qw( basename ); sub help { my $prog = basename($0); print("usage: $prog -t [options]\n"); exit(0); } sub usage { my $msg = shift || ''; my $prog = basename($0); die("${msg}Use $prog --help for help\n"); } GetOptions( 'help|h|?' => \&help, 'test=s' => \$option_test, ) or usage(); defined($option_test) or usage("Missing argument -t\n");
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Requiring option values in Getopt::Long
by zwon (Abbot) on Aug 20, 2009 at 18:31 UTC |