Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
I did, however, encounter a snag with this method. I have to check for existence of the key within the referenced hash before attempting to access it otherwise Perl warns me about accessing an uninitialized value if the argument was not set by the user

If the caller doesn't pass the values you expect, you'll get a warning in the traditional style too:

$ perl -wE 'sub f { my ($v) = @_; say $v }; f()' Use of uninitialized value $v in say at -e line 1. $

In the end the level of checking you want to do is a matter of style, and intended audience.

In Perl 5 code I usually only check the arguments where I suspect the subs might get called wrongly. In Perl 6 I just write the signatures as expressive as possible, and let the compiler and runtime do the checking for me.


In reply to Re: sub argument passing? (TIMTOWTDI) by moritz
in thread sub argument passing? (TIMTOWTDI) by temporal

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 contemplating the Monastery: (8)
    As of 2014-12-25 10:12 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (160 votes), past polls