Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: How do I prototype a function with a varying number of arguments?

by AnomalousMonk (Archbishop)
on Jul 29, 2011 at 18:00 UTC ( [id://917510]=note: print w/replies, xml ) Need Help??


in reply to How do I prototype a function with a varying number of arguments?

Why do you want to use prototypes? They almost never do just what you want and/or expect. In any event, optional parameter values must be handled in the same way: by checking in the function that a defined (or otherwise valid) value has been passed.

>perl -wMstrict -le "sub opt_w_proto ($;$) { my ($x, $y) = @_; $y //= 42; print qq{x $x y $y}; } ;; sub opt { my ($x, $y) = @_; $y //= 42; print qq{x $x y $y}; } ;; opt_w_proto(7); opt_w_proto(7,0); ;; opt(7); opt(7,0); " x 7 y 42 x 7 y 0 x 7 y 42 x 7 y 0
  • Comment on Re: How do I prototype a function with a varying number of arguments?
  • Download Code

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2024-04-19 21:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found