exists on a slice, I never thought of trying it, but it certainly sounds like a nice feature request. (No idea how easy it is though, but you can always ask.)
But the hideous line is worse than needed. Just do this:
if (grep !exists $args->{$_} @mandatory_args) {
printUsage() and exit;
}
which looks much better. No need to
map and then
grep, just
grep!
Now for a few stylistic points.
- I don't like nesting logical assertions to save lines. Combining && and if used for program flow on one line is hard on maintainance programmers, break it up.
- Of the various ways of calling a function, the only one to avoid is &foo. Unless you need the implicit parameter passing, avoid it. You don't want someone picking up the habit without knowing about the gotcha.
- End of line indentation is the only kind of indentation I object to. As pointed out in Code Complete, it results in very rapidly getting deep nesting, it breaks the easily seen connection between depth of indentation and depth of logic, and it represents a stylistic maintainance problem; you can't edit the code without unnecessary playing around with indentation on following lines.
- I returned to using an array of mandatory arguments in the test in the hope that you could reuse that array in the usage statement. If possible, it is nice to have your usage statement automatically synchronized with your test for correct usage. The rest of the details, in fine mathematical tradition*, are left as an exercise.
BTW if you can figure out a good way to handle the last point, I am all ears. This is a variant on the problem I addressed at
Re (tilly) 2: passing subroutine arguments directly into a hash. The solution I outline there works, but the messages are inappropriate for a user interface, rather it is an internal interface to help programmers debug.
* According to tradition, when mathematicians come to a point they need in a text, whose proof they can't remember, they make it into an exercise for the reader. :-)
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.