Next up in the Perl Module of the Day series is Getopt::Long::Descriptive. It gives you the ability to have options passed to your programs like Getopt::Long, but allows you to also set up some descriptive text to be displayed when you need it, formatted in a nice, consistent way.
Use is pretty straight-forward. Call it via:
my ($opt, $usage) = describe_options(
'%c %o',
[ 'id|i=i', 'the id to look for', { default => 1 } ],
[],
[ 'help|h', 'some help messages' ]
);
print($usage->text), exit if $opt->help;
This will print out a nice help message with both the long and short options detailed, along with their descriptions so the users actually understand what the option actually does.
Here’s the exact output from the above code, written as ‘descriptive.pl’:
descriptive.pl [-hi] [long options...] -i --id the id to look for -h --help some help messages
You’ll notice that this spits out information based on the above information you supplied, just as you’d expect. It’s up to you to determine how detailed you want to make the descriptions. The options work just like Getopt::Long do, so you can have items that you specify multiple times, using arrays (arrayrefs, really) etc. You’re even offered the ability to give each option a default value.
Recently, I was listing to an older episode of “The Dev Show“, with Jason Seifer and Dan Benjamin, where they stated that perl was a write once, read never language. While this module won’t keep you from read never, it will at least help you later when you do have to read it again, an also when you have to run it again for the first time in months.
Any module that helps keep your sanity in line is a good module for me.

Other related posts: