Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Arrays and Hashes Mapping

by jesuashok (Curate)
on Dec 08, 2004 at 10:34 UTC ( #413146=perlquestion: print w/ replies, xml ) Need Help??
jesuashok has asked for the wisdom of the Perl Monks concerning the following question:

@list = ( one , two , three ); %hash = ( one => 1 , two => 2 , three => 3 ); foreach (@list) { if ( $hash{$_} ) { $_ = '' ; } }
I want the above method to be simplified by using map or something else But it should be simple ( i,e ) one line. If the key is available in hash then the value should be removed from the list
Anthony Jesu Ashok Majoris Systems Ltd Bangalore

2004-12-08 Janitored by Arunbear - added code tags, as per Monastery guidelines

Comment on Arrays and Hashes Mapping
Download Code
Re: Arrays and Hashes Mapping
by pingo (Hermit) on Dec 08, 2004 at 11:15 UTC
    If I understand you correctly, perhaps something like this:

    @list = ('one' , 'two' , 'three'); %hash = ( one => 1 , two => 2 , three => 3 ); @list = grep { !$hash{$_} } @list;
      Better use exists here, so that ( zero => 0, empty => '' ) won't give you false positives:
      @list = grep { !exists $hash{$_} } @list;
      --kap

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://413146]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2015-07-07 02:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (86 votes), past polls