Beefy Boxes and Bandwidth Generously Provided by pair Networks chromatic writing perl on a camel
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Passing by Named Parameter

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

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


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
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.