in reply to Re (tilly) 1: built-ins sometimes iterating over a list, sometimes not
in thread built-ins sometimes iterating over a list, sometimes not
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re (tilly) 3: built-ins sometimes iterating over a list, sometimes not
by tilly (Archbishop) on Nov 08, 2001 at 20:28 UTC | |
by demerphq (Chancellor) on Nov 08, 2001 at 23:27 UTC | |
by tilly (Archbishop) on Nov 09, 2001 at 01:49 UTC |