Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

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

Since this is the realm of coding style, it's almost certainly all personal preference. ;>

I know that I tend to prefer using a hash once I get above three or four parameters. Some of the reasons that I can think of why I tend to do so:

  • I don't have to remember the order in which the parameters are passed. Granted, I do have to remember the names of the keys, but I think that's a small sacrifice. One can also use the same two or three key names for multiple subroutines ot make it easier to remember.
  • Self-documentation. As you hinted at, to me it's clearer what:load_foo(filename=>"bar",template="baz", debug=>1); is doing than: load_foo("bar","baz",1); does.
  • It means I can establish defaults for some parameters rather easily. To use the same fictitious load_foo subroutine:
    sub load_foo { my %args = ( # Defaults template => "zort", debug => 0, @_); ... # yadda yadda yadda }
  • No reordering. If you're using lots of individual scalars, and you find out you don't need the third our of seven of them -- you'd better make sure you take that one out of all of the places where you call it, or you're up a creek. With a hash, it's not so much of an issue.

*shrug* All of the above are just personal preferences, yes. Do what seems to work best for you.

perl -pe '"I lo*`+$^X$\"$]!$/"=~m%(.*)%s;$_=$1;y^`+*^e v^#$&V"+@( NO CARRIER'


In reply to Re: Accessing Subroutine Arguments by Chmrr
in thread Accessing Subroutine Arguments by vek

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 wandering the Monastery: (4)
As of 2024-04-18 21:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found