On Fri, Sep 30, 2005 at 10:08:51AM -0400, Jeff 'japhy' Pinyan wrote: > On Sep 30, Mark Martin said: > > >I want to compare the elements of an array with the keys in a hash. If > >matches are found, I want to store the values associated with the > >matched keys in an array for future processing : > > > > my @storage_array = (); > > foreach $item(@original array) { > > if (exists $original_hash{$item}) { > > push(@storage_array, ?????? ) > > } > > } > > Your ?????? should just be $original_hash{$item}, I expect, although this > code could be written far more succinctly as a map(): > > my @storage_array = map { > exists $original_hash{$_} ? $original_hash{$_} : () > } @original_array; >
... or grep my @storage_array = grep { exists $original_hash{$_} } @original_array; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>