Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Use Getopt::Long even if you don't think you need to

by almut (Canon)
on May 19, 2008 at 08:12 UTC ( [id://687303]=note: print w/replies, xml ) Need Help??


in reply to Use Getopt::Long even if you don't think you need to

Yes, I have to admit I also occasionally had hand-hacked parsing for those one or two options. In the meantime, I've learned from those mistakes, i.e. I use Getopt::Long as soon as the first option idea pops up in my mind... because I know it won't be the last. Not only is it less work, it's also so much more flexible and DWIM.

On the other hand, I'd say it's never too late. And, as any option parsing is typically done in some central place anyway (rather than being scattered all over the program), replacing it with Getopt::Long has usually been a matter of less than five minutes — unless you postpone that decision until your tool has as many options as gcc...

Replies are listed 'Best First'.
Re^2: Use Getopt::Long even if you don't think you need to
by jbisbee (Pilgrim) on May 22, 2008 at 17:41 UTC
    I love having long options because it provides a better description of what the options are when someone views your program for the first time. It simply is a great user interface tool when someone comes across on of your scripts for the first time.

    I start every new command line perl script with this template...

    #!/usr/bin/perl use strict; use warnings; use Getopt::Long; use Pod::Usage; Getopt::Long::Configure("no_ignore_case"); GetOptions( 'h|help'=> sub { pod2usage( { -verbose => 1, -input => \*DATA } ); exit; +}, 'H|man' => sub { pod2usage( { -verbose => 2, -input => \*DATA } ); exit; +}, ); __DATA__ head1 NAME =head1 SYNOPSIS Options: -h --help Display this help -H --man Display detailed help (examples) =head1 EXAMPLES =head2 First Example...

    -biz-

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-20 14:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found