Ok. So, I'm stupid about using the extra map. I'm also stupid about using the wrong invocation of the function. I'm so used to method calls which don't need the & or the () that I forgot which is supposed to be used when calling a 'normal' function. :-)

I find that nesting logical assertions helps the reader understand what a string of maps and greps and sorts is doing. Yes, in theory, the programmer is supposed to use intermediate variables, but no other language has the same piping that Perl has, so Code Complete never addressed the issue. I've seen merlyn and theDamian both use a similar form to do the Orcish manauver or Schwartzian transforms. *shrugs*

As for mandatory args ... *sighs* This is similar to another problem I have that I posted somewhere, but don't have the motivation to find.

*ponders* Wouldn't something like the following work?

sub printUsage { my ($mandatory, $optional) = @_; print "Usage: $0\n"; print "-$_ ", uc $_, " " for @$mandatory; print $/; print "[-$_ ", uc $_, "]" for @$optional; print $/; }

Of course, the formatting isn't as good. I'll leave that as an exercise for the reader. *grins*

Update: I changed how I did the calls into Getopt::Long. Please critique.

my @mandatory = qw(user to_db to_sid to_site); my @optional = qw(password vendor type model); my @default = qw(from_db from_sid); our $from_db = "some_db"; our $from_sid = "some_sid"; my $args = {}; my $rc; { no strict 'refs'; $rc = GetOptions($args, (map { "${_}=s" } @mandatory), (map { "${_}:s" } @optional), (map { ("${_}=s", \${"$_"}) } @default), ); } printUsage(\@mandatory, \@optional, \@default) unless $rc; printUsage(\@mandatory, \@optional, \@default) if grep !exists $args->{$_}, @mandatory;

------
We are the carpenters and bricklayers of the Information Age.

Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.


In reply to Re: Re (tilly) 1: built-ins sometimes iterating over a list, sometimes not by dragonchild
in thread built-ins sometimes iterating over a list, sometimes not by dragonchild

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.