Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
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 chilling in the Monastery: (7)
As of 2014-12-25 17:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (161 votes), past polls