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.


In reply to Re^2: Mixing command line arguments by revdiablo
in thread Mixing command line arguments by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.