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



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


.



Relevant Pages

  • Re: increasing counter whithin loop?
    ... > the loop? ... there's nothing preventing you from doing e.g.: ... # set skip to true to skip the next iteration ... Prev by Date: ...
    (comp.lang.ruby)
  • Re: .NET Socket
    ... Rahul Anand wrote: ... > But later I noticed that if in last iteration the bytes come to be less than ... can call Socket.Shutdown in another thread to interrupt that blocking call. ... Prev by Date: ...
    (microsoft.public.dotnet.languages.csharp)
  • I dont understand what glob does here
    ... invocation, I would have seen one "file" in each iteration, not 2 ... Why does the behavior change between iterations of the foreach loop ... I've read through glob and File::Glob and I haven't seen anything ... Prev by Date: ...
    (comp.lang.perl.misc)
  • Re: removing list comprehensions in Python 3.0
    ... Hrm, okay, so generators are generally faster for iteration, but not ... for making lists(for small sequences), so list comprehensions stay. ... Prev by Date: ...
    (comp.lang.python)
  • Re: Strange query problem php/mysql
    ... iteration its contents are unpredictable. ... Fix this first. ... chars. ... Prev by Date: ...
    (comp.lang.php)