Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^3: Distinguish between missing and undefined arguments with subroutine signatures

by choroba (Cardinal)
on Dec 27, 2020 at 18:08 UTC ( [id://11125804]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Distinguish between missing and undefined arguments with subroutine signatures
in thread Distinguish between missing and undefined arguments with subroutine signatures

Oh, sorry, I didn't get it.

Why do you need it?

It seems you don't want an optional argument with a default value, you want a subroutine that knows whether setting the default value was triggered. It's hard to do it with just the optional argument, as it's a single value, but you're interested in two values: the value itself and the boolean telling whether the default value was triggered. Both your solutions introduce such a value (whether it's the scalar @_ or the additional lexical variable). I'm not sure which one I'd prefer, but I'd probably add a comment to both of them.

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
  • Comment on Re^3: Distinguish between missing and undefined arguments with subroutine signatures
  • Download Code

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-23 07:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found