[tpm] Command line option processing

Uri Guttman uri at stemsystems.com
Sat Jan 5 14:18:56 PST 2008

>>>>> "a" == arocker  <arocker at vex.net> writes:

  a> getopt ("v");           # primitive help facility -v is only option

  a> if ( $Getopt::Std::opt_v ) {

where did you get the notion that Getopt::Std is the namespace where
options are set??

  a> I've delved into the Camel, the Cookbook, Nutshell and every other
  a> grimoire I can find, so public humiliation is the only route left. What
  a> idiotic error am I making?

how about rtfm?

       use Getopt::Std;

       getopt(’oDI’);    # -o, -D & -I take arg.  Sets $opt_* as a side effec
       getopt(’oDI’, \%opts);    # -o, -D & -I take arg.  Values in %opts
       getopts(’oif:’);  # -o & -i are boolean flags, -f takes an argument
                             # Sets $opt_* as a side effect.

i see nothing mentioning that namespace. why don't you just check

also it is much better to pass in a hash ref and get all the options in
the hash. then you can pass them around as one collection to subs, you
don't dirty up the name space and you can even iterate over the ones set
to print them out. i don't write many scripts which use options but
having all the options in a single hash is by far the best way to manage
them. you can even set defaults and such with some of the getopt
variation in that same hash. rtfm for more on that. 

was that humiliating enough? :)


Uri Guttman  ------  uri at stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org

More information about the toronto-pm mailing list