Re: how to test if an element belongs to an array or hash



Jim Keenan wrote:

> biomahui@xxxxxxxxx wrote:
>> Thanks.
>>
>> Another question,
>> Is there a way to find the keyvals from their values without using
>> iteration. For instance;
>>
>> $set{"apple"}="fruit";$set{"pear"}="fruit";$set{"banana"}="fruit";$set
>> {"beef"}="meal";
>>
>> I need to find "apple","pear" etc from "fruit".
>
> my @fruit;
> for (keys %set) {push(@fruit, $_) if $set{$_} eq 'fruit'; }

You just reinvented grep :-) (or better :-( ).

--
John Small Perl scripts: http://johnbokma.com/perl/
Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html

.