Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: comparing array elements to hash keys

by CukiMnstr (Deacon)
on Jul 02, 2003 at 14:21 UTC ( #270812=note: print w/replies, xml ) Need Help??


in reply to comparing array elements to hash keys

you have to change the foreach in your inner loop for a while (right now it is only iterating once over the hash), or change the foreach inner loop to use keys %hash instead of each %hash (so it iterates over every key). Also, you are using == to compare the elements in the array to the keys in the hash, so this will only work for numeric values. You could try something like this instead:
foreach my $thing (@array) { if ( exists $hash {$thing} ) { push @new_array, $hash {$thing}; } }

hope this helps,

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2020-02-28 22:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What numbers are you going to focus on primarily in 2020?










    Results (127 votes). Check out past polls.

    Notices?