Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Perl: the Markov chain saw
 
PerlMonks  

Comment on

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others taking refuge in the Monastery: (11)
    As of 2014-04-21 15:06 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      April first is:







      Results (495 votes), past polls