Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Seeking Getopt recommendations - anyone used Getopt::Easy?

by ides (Deacon)
on Jan 09, 2007 at 14:11 UTC ( [id://593727]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://593727]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-04-25 17:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found