Esteemed monks, I seek your wisdom.
If you have a lot of arguments that you need to pass to a subroutine, is it preferrable to pass & access them individually:
do_stuff($foo, $bar, $foo_too, $bar_too, $foo_who_poo);
sub do_stuff {
my ($foo, $bar, $foo_too, $bar_too, $foo_who_poo) = @_;
}
Or pass & access by named parameter:
do_stuff(one=>$foo, two=>$bar, three=>$foo_too, four=>$foo_who_poo);
sub do_stuff {
my %args = @_;
}
Or is it purely personal preference?
I'm starting to get some 'feature creep' in my code and keep adding subroutine arguments as the specifications change. I'm thinking at the very least if I pass by named parameter I'll have some 'self-documenting' code.
What do you do?
-
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.