In my Work Backup program I configure the script with a list of things to do, thus:
my @locations= ( [ source => 'D:\\dev' ], [ docs => 'D:\\My Documents' ], [ source => 'F:\\dev' ], [ docs => 'F:\\Documents' ], [ norule => 'D:\\Program Files\\util'] );
Now, I want to make it more complex, allowing for multiple rules and modifiers to be applied to one item. So, what's a good way to do this?

In Tk, a general mechanism is used for passing arguments that begin with a dash, followed by arguments for that particular flag. Some general code pulls that out and deals with it.

[ qw ( -this -that 5 6 -other /path/etc/foo ) ],
Another idea is to have one item per list element, period, and if it had arguments include it in a nested list. E.g.
[ '-this', [ that => 5, 6 ], '-other', '/path/etc/foo' ],
This is easier to process and clear that the 5 and 6 go with the 'that'.

In the script, each modifier will be implemented via a callback, which takes the extra arguments too, and the callback can modify the job's object state in some way.

Does anyone else have any suggestions on a good way to do this? "good" for both the user configuring the thing, and the implementation.

—John


In reply to Ways of Passing Configuration Parameters by John M. Dlugosz

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.