Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: comparing array elements to hash keys

by CukiMnstr (Deacon)
on Jul 02, 2003 at 14:21 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://270812]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-25 17:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found