Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-20 02:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found