in reply to Re: Mixing command line arguments
in thread Mixing command line arguments

I realize this wasn't an integral part of your example, but your series of push lines would be very disheartening for me to see in real code. For something like that, I'd much rather see a data-driven solution. Something along the lines of:

my @args; my %chkopts = ( help => $help, b => $backup, u => $upd_sybase, s => $silent, ); while (my ($k, $v) = each %chkopts) { next unless defined $v; push @args, $v ? "--$k" : "--no$k"; } my %chkargs = ( update => $update, server => $server, user => $user, password => $password, ); while (my ($k, $v) = each %chkargs) { next unless defined $v; push @args "$k=$v"; }

This way, the data (i.e., which args and opts need to be checked, and what their values are) is separated from the policy (i.e., build an array holding the defined args/opts and their values, using a certain syntax for args and a different syntax for opts). Adding new args or opts would be a much simpler process, and checking the data for errors would be easier. At some point, this data could even be moved out of the code altogether, and put in a config file.