Re: how to test if an element belongs to an array or hash
- From: Brian Wakem <no@xxxxxxxxx>
- Date: Tue, 31 May 2005 18:43:01 +0100
biomahui@xxxxxxxxx wrote:
> Thanks.
>
> Another question,
> Is there a way to find the coevals 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".
> Thanks!
It sounds like you are not using an efficient data structure for your needs.
Can I suggest a hash of hashes:-
my %set = ( fruit => { apple => 1, pear => 1, banana => 1 },
meal => { beef => 1 },
);
print "$_\n" for keys %{$set{'fruit'}};
--
Brian Wakem
.
- Follow-Ups:
- 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: biomahui
- Re: how to test if an element belongs to an array or hash
- 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
- 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: Re: how to test if an element belongs to an array or hash
- 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):
Relevant Pages
|