Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: Storing multiple arguments in a data structure that allows for future expansion

by Herkum (Parson)
on May 02, 2007 at 11:59 UTC ( #613157=note: print w/replies, xml ) Need Help??

in reply to Storing multiple arguments in a data structure that allows for future expansion

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.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://613157]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2021-07-23 19:01 GMT
Find Nodes?
    Voting Booth?

    No recent polls found