What I've learned from fellow monks and from reading
'Code complete' from McConnell, it appears to be the
best to make your interfaces as "independent" as possible.
So in general, only use the interface (@_) to pass data
between your package and the user-sub. Globals could be
messed with by other subs, and so mess up your code.
Moreover, they are harder to maintain in the long run.
The cleanest way to go is indeed the hashkeys way.
Several advantages: Clean namespace, extendible/ flexible,
not dependent on the order of args. You say it uglifies
the user code. Well, that may be true
(qw/beaty eyes beholder/), but it is very readible:
sub user_sub(
my %input = @_;
$input{numberX} * $input{multiplier} + $user_glob;
}
This is a bit more writing than your examples maybe,
but very clear.
And I think you summed up the pro's/contra's pretty well.
Try to think more like: "is it clean/functional code?"
than "is the code very nicely looking?". At least,
that would be my approach.
Jeroen
"We are not alone"(FZ)
Fixed error
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.