Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

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.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (8)
As of 2016-06-26 15:53 GMT
Find Nodes?
    Voting Booth?
    My preferred method of making French fries (chips) is in a ...

    Results (330 votes). Check out past polls.