Re: how to test if an element belongs to an array or hash
- From: John Bokma <john@xxxxxxxxxxxxxxx>
- Date: 31 May 2005 18:42:37 GMT
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
.
- References:
- how to test if an element belongs to an array or hash
- From: biomahui
- Re: how to test if an element belongs to an array or hash
- From: John Bokma
- Re: how to test if an element belongs to an array or hash
- From: biomahui
- Re: how to test if an element belongs to an array or hash
- From: Jim Keenan
- how to test if an element belongs to an array or hash
- Prev by Date: Re: how to test if an element belongs to an array or hash
- Next by Date: how to sort hash by value, where value is a valid date
- Previous by thread: Re: how to test if an element belongs to an array or hash
- Next by thread: Re: how to test if an element belongs to an array or hash
- Index(es):