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 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'; }

Jim Keenan

.



Relevant Pages

  • Re: how to test if an element belongs to an array or hash
    ... Jim Keenan wrote: ... >> Is there a way to find the keyvals from their values without using ... > my @fruit; ... Prev by Date: ...
    (comp.lang.perl.misc)
  • Re: how to test if an element belongs to an array or hash
    ... > Is there a way to find the keyvals from their values without using ... Not without iteration, but you can use grep to speed it up and hide it ... Anno ... Prev by Date: ...
    (comp.lang.perl.misc)
  • 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)