[tpm] Command line option processing

Michael Graham magog at the-wire.com
Sun Jan 6 12:51:56 PST 2008


> > also it is much better to pass in a hash ref and get all the
> > options in
> 
> Too complicated a solution for the simple problem. 

Doing it the "right" way first makes it more likely that your program
will grow sanely when you add additional options in the future.

> Also, if I can't
> solve a problem with a simple variable, what's the chance of solving
> one using a hash?

You'd be switching from Getopt::Std to Getopt::Long, which is a
completely different options-processing module.  

So, with that in mind, I'd rewrite your rhetorical question as:  "If I
can't solve the problem with one module, what's the chance of solving
it using a different module?"

It's a shame, but the Getopt::* namespace is cluttered with dozens of
unrelated and semi-related modules, all with their own interfaces.  I
even wrote one myself (but thankfully never published it).  I think it
was called something like Getopt::Simple::MyWay::Dammit.

It looks like Getopt::Std comes bundled with perl and is pretty
ancient.  For one thing its interface recommends using global variables
(which tend to be shunned these days).  For another thing, it doesn't
"use strict" itself.  That doesn't mean that it's buggy code, just that
it's pretty old; the "::Std" moniker should be taken with a grain of
salt.


Michael



-- 
Michael Graham <magog at the-wire.com>


More information about the toronto-pm mailing list