pileofrogs has asked for the wisdom of the Perl Monks concerning the following question:
I've run across several functions that handle complex args in a way that I like. They will take a few args as just args or they can take a hash ref (and maybe a hash) or maybe they can handle a combination. Like so:
blargh('/tmp/foo'); # or blargh('/tmp/foo','pileofrogs@example.com'); # or blargh('/tmp/foo','pileofrogs@example.com', { enable_giant_squid => 1, squid_name => 'Bob' }); # or even blargh( file => '/tmp/foo', email => 'pileofrogs@example.com', enable_giant_squid => 1, squid_name => 'Bob');
The args that you always or almost always set can be set by normal positional args, but more detailed tweaks can be passed in a hash ref or you can pass everything as a hash.
Anyway, I've seen this (or something like this) in several places and I'd like to do it too. Is there a recommended way to handle this? A best practice?
Thanks!
--Pileofrogs
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: function w complex args
by fmerges (Chaplain) on Mar 13, 2007 at 23:29 UTC | |
|
Re: function w complex args
by ferreira (Chaplain) on Mar 14, 2007 at 02:31 UTC | |
|
Re: function w complex args
by GrandFather (Saint) on Mar 13, 2007 at 23:32 UTC | |
|
Re: function w complex args
by jdtoronto (Prior) on Mar 14, 2007 at 02:47 UTC | |
|
Re: function w complex args
by izut (Chaplain) on Mar 14, 2007 at 18:04 UTC |