Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Passing by Named Parameter

by Coruscate (Sexton)
on Jan 27, 2004 at 05:37 UTC ( [id://324357]=note: print w/replies, xml ) Need Help??


in reply to Passing by Named Parameter

You could always use something like what I just threw together below. But like you said, the code becomes repetitive. Here it is: provides both parameter checking and default values.

sub do_something { my %default = ( # declare all valid parameter foo => 'foo argument', # names, providing a default bar => 'bar argument', # value at the same time (set baz => undef # to undef for no default) ); my %params = (%default, @_); for (keys %params) { warn "unknown parameter '$_' passed to do_something()" unless exists $default{$_}; } # now do stuff. }

Log In?
Username:
Password:

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

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

    No recent polls found