Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: Re: GetOpt::Long usage style

by demerphq (Chancellor)
on Mar 08, 2003 at 19:58 UTC ( #241429=note: print w/ replies, xml ) Need Help??

in reply to Re: GetOpt::Long usage style
in thread GetOpt::Long usage style

Yeah I do use this style as well. However it still presents duplication when you want to provide defaults or multiple names or types for options (which rules out a quick key %opts), in fact its worse because you dont have compile time var name checking of the var names if they get out of synch. In other words the connection between destination and source becomes too loose and it becomes really easy to make a subtle error

my %opt={verbose=>0,all=>0); GetOptions(\%opt,'talkative|verbose','everything|all');

So what happens if we werent careful and do it like


Oops, now the --all options goes to the wrong place.

Anyway, I still would use the %hash style as well for some situations, and as the interface to Getopt::Long is so flexible you can mix the two:

GetOptions(\%opts,'Debug=i'=>\(my $Debug=0),'verbose','all');

And then theres also using subs for the options... Mmm fun!


Comment on Re: Re: GetOpt::Long usage style
Select or Download Code
Replies are listed 'Best First'.
Re3: GetOpt::Long usage style
by dragonchild (Archbishop) on Apr 08, 2003 at 22:50 UTC
    Personally, I tend to keep thingsl ike synonyms in a data structure of their own. So, I might do something like:
    my %options = ( verbose => 0, everything => 1, ); my %synonyms = ( verbose => [ qw( talkative )], everything => [ qw( all )], ); GetOptions( \%options, ( map { join\('|', $_, @{ $synonyms{$_} || []}) } keys %options ), );
    This way you can, at a glance, see exactly what your synonyms are, laid out nice as can be. A similar thing can be done with the "=i", "=s", etc.

    We are the carpenters and bricklayers of the Information Age.

    Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

    Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (9)
As of 2015-10-13 09:48 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (299 votes), past polls