In that case you might simply pass all named args inside a hash_ref and all positional args inside an array reference. Downside of all this is of course an extreme amount of diffrently shaped brackets getting used ...
sub get_args {
if (scalar(@_) == 1) {
if (ref($_[0]) eq 'HASH') {
return "got named args!\n";
} elsif (ref($_[0]) eq 'ARRAY') {
return "got positional args\n";
} else {
die "argument wasn't a hash or array reference!\n";
}
} else {
die "got more than one arg!\n";
}
}
sub named_or_positional {
print get_args(@_);
}
named_or_positional({foo => 'avalue' , bar => ['a', 'b']});
named_or_positional(['whatever' , 'we', 'are', 'passing']);
named_or_positional('whatever' , 'we', 'are', 'passing');
Then you would have to check whether there is a single hash_ref or a single array_ref for determining whether it's positional or named. Any other case than a single hash or array ref would have to be considered a error.
If you don't mind the additional overhead of square/curled brackets, then it would allow you simple differentiation of named an positional args.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.