UPDATED
For the reason that the array is coming in from user input (Getopt::Long), so I don't want to add unknown options to my final hash.
I want to pare down the entries in the hash to the mimimum amount of keys corresponding to only known parameters that i have been given.
cheers though,
Sorry the first draft of this reply was gibberish
my %opts;
my %locs = map { $_ => 1 } ('do', 'ny', 'kw');
my %sect = ('uid' => 1, 'email' => 'a', 'username' => 'a');
my $USAGE = qq(
USAGE: perl launch.pl (-l=<location>)+ (-d=<data>)+
Where -l=<location> = [do|kw|ny] = one or more times
-d=<data_type> = [uid|email|username] = one or more times
);
die $USAGE unless (scalar(@ARGV) >= 2);
GetOptions(\%opts, "l=s@", "d=s@");
die $USAGE unless (defined $opts{'l'});
die $USAGE unless (defined $opts{'d'});
%locs = map { $_ => $locs{$_}} grep defined $locs{$_}, @{ $opts{'l'}
+}; # strips out keys from hash if
%sect = map { $_ => $sect{$_}} grep defined $sect{$_}, @{ $opts{'d'}
+}; # not requested by user
die $USAGE unless scalar keys %locs > 0;
die $USAGE unless scalar keys %sect > 0;
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.