* Eric Wilhelm <[EMAIL PROTECTED]> [2005-06-17 01:35]: > >I don’t understand. If there was no need to be able to say > >“--foo --no-foo”, then why do both exist? > > No, no, no. Start over. > > 1. There is a need. > 2. It doesn't matter what order the user gives the options in, > the result should be the same.
Wait, why start over? I’m asking what this need is. I want to know which things we are trying to achieve. If we don’t know that, how will we know when we achieved them? > Did you read the essay about why order doesn't matter? I did now and I didn’t see anything new that hasn’t been mentioned in this thread already. First, to get the show stopper out of the way, your proposed model is trivial to implement in terms of Getopt::Long. my $verbosity = 5; GetOptions( 'v|verbose' => \( my $opt_verbinc = 0 ), 'no-verbose' => sub { $verbosity = 0 }, ); $verbosity += $opt_verbinc; $verbosity = 10 if $verbosity > 10; Clear, self-documenting code. Second, you are using a weird and unusual example to support your arguments: a ranged variable option that is incremented using binary switches. The only case where I’ve ever seen that model used is precisely for the “-v” verbosity switch. The first I encountered it, I thought it was strange. Of note that a program typically has only one switch which behaves this way, and that I’ve never seen anyone write “-vxyvjvkv” rather than “-vvvvxyjk”. Thus, I posit that this model is wrong in most cases. It seems that accumulative switches are all that you are really talking about. I therefore further posit that the switch you called “--no-verbose” is a misnomer. It should be called “--start-verbose=0”, which indeed should be parsed in precedence order rather than command line order. “--foo --no-foo” makes sense in mathematic terms, not in linguistic ones. Certainly it’s not anywhere as obvious an expression of your intent as something like “--foo --start-foo=0” is. This model is even easier to implement in terms of Getopt::Long. GetOptions( 'v|verbose' => \( my $opt_verbinc = 0 ), 'start-verbose=i' => \( my $opt_startverb = 5 ), ); my $verbosity = $opt_startverb + $opt_verbinc; And no, you can’t tell what option comes from an alias and which doesn’t. Even if you could, that wouldn’t cover cases like my @cmd = qw( foo --bar --baz ); if( $something ) { system @cmd, qw( blah blah ) } elsif( $other ) { system @cmd, '--wibble', @wibble } elsif( $whatev ) { system @cmd, '--wubble', @wibble } else { system @cmd, qw( --no-bar blah blah ) } What you’re asking the “--no-foo” mechanism to do for you it neither something it’s meant to do nor something it’s a good literary choice for. Regards, -- #Aristotle *AUTOLOAD=*_=sub{s/(.*)::(.*)/print$2,(",$\/"," ")[defined wantarray]/e;$1}; &Just->another->Perl->hacker;