Don't use an array, use a hash reference. It will be so much easier. Take this example,

processOne('Sample', 2, '', '', 1000, '', 'write', 'read', 'cache');

If you use an array, you are dependent on the order of the array to pass the arguments. Switches you would not need, you have to include a value for them anyways just to make sure the array is the correct structure. It becomes easy to miss a value and you will spend alot of time trying to identify what is the problem. In addition, none of the values are descriptive so you have no idea what they mean just by looking at them. If you have to go back, you may forget the order and someone else who needs to change it will have a hard time trying to figure it out.

Using a hash reference makes it easier to read and add switches.

processOne({ file_type => 'Sample', read_lines_to => 1000, write_output => 1, # TRUE cache_file => 1, # TRUE cache_in_memory => 0, # FALSE fetch_column_no => 2,

The next person who comes along at least has a chance of identifying the values and what they are supposed to used for.


In reply to Re: Storing multiple arguments in a data structure that allows for future expansion by Herkum
in thread Storing multiple arguments in a data structure that allows for future expansion by appleb

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.