Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: sub argument passing? (TIMTOWTDI)

by moritz (Cardinal)
on Sep 13, 2012 at 18:50 UTC ( #993560=note: print w/ replies, xml ) Need Help??


in reply to sub argument passing? (TIMTOWTDI)

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.


Comment on Re: sub argument passing? (TIMTOWTDI)
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2014-11-22 14:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (123 votes), past polls