in reply to Seeking Getopt recommendations - anyone used Getopt::Easy?

I agree with what's been said here. I too haven't used Getopt::Easy, but use Getopt::Long all of the time. The main reason to not use Getopt::Easy that I can see would be that it isn't a CORE module and would need to be installed on every machine where it is used.

While we're sharing coding idioms.... here is what I always do for commandline arguments:

use strict; use Getopt::Long; # Main body eval { my $options = { 'help' => 0, 'verbose' => 0, 'config' => '/etc/myapp.conf', }; GetOptions( 'help' => \$$options{help}, 'verbose!' => \$$options{verbose}, 'config=s' => \$$options{config}, ); }; print "ERROR: $@" if $@;

This lets you set defaults for your options and GetOptions() handles any commandline overrides by the user.

Frank Wiles <frank@revsys.com>
www.revsys.com

Replies are listed 'Best First'.
Re^2: Seeking Getopt recommendations - anyone used Getopt::Easy?
by gaal (Parson) on Jan 09, 2007 at 17:28 UTC
    What's the purpose of eval { ... }; print ... if $@?

    It's almost always better to let the program die if it received invalid input. You'll get the same error message (without the "ERROR: " prefix) on standard error.

      Sorry I should have been more clear. I use that standard setup and include all of the program's logic in the eval, just after the GetOptions() call. I do this in case I want to trap out the error and do something more special with it later.

      Frank Wiles <frank@revsys.com>
      www.revsys.com