Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Re: Mapping array over a hash

by agoth (Chaplain)
on Jul 20, 2001 at 18:02 UTC ( [id://98408]=note: print w/replies, xml ) Need Help??


in reply to Re: Mapping array over a hash
in thread Mapping array over a hash

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;

Replies are listed 'Best First'.
Re: Re: Re: Mapping array over a hash
by dragonchild (Archbishop) on Jul 20, 2001 at 18:09 UTC
    Umm... you won't be. The only keys in %hash1 that are ever checked are values that exist in @ary. I'm assuming that @ary is the list of allowable parameters. That would mean that any values in %hash1 that didn't exist in @ary would never make it into %hash2. And, likewise, any values in @ary that don't exist in %hash1 don't make it into %hash2.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://98408]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-25 07:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found