Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Default values in functions arguments

by chromatic (Archbishop)
on Sep 27, 2000 at 23:07 UTC ( [id://34263]=note: print w/replies, xml ) Need Help??


in reply to Default values in functions arguments

I've seen something similar with constructors. A hash is set up with default values, and the constructor can take a hash or hash ref as an argument.
sub new { my $class = shift; my $hash_ref = shift; my $self = { value => '100', color => 'charcoal', }; @$self{keys %$hash_ref} = (values %$hash_ref) if (defined %$hash_r +ef); bless($self, $class); }
Passing in a list like you have won't let you do the nice list slice operation, and it's possible to pass in new values than what are defined.

Still, it's a pretty nice technique, and there's no reason it has to be limited to constructors. In your case, it just might work.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2024-03-28 18:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found