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
In reply to function w complex args by pileofrogs
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |