Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Like in hashes, do we have something like exists in arrays as well.

by rjimlad (Acolyte)
on Jul 19, 2002 at 20:28 UTC ( [id://183443]=note: print w/replies, xml ) Need Help??


in reply to Like in hashes, do we have something like exists in arrays as well.

Yes. Grep.
my @a=('a' .. 'z'); print scalar grep {$_ eq "q"} @a;
...this is actually equivalent to a foreach loop, so don't do it for big arrays. There is no quick way to do that - if you must, use hashes instead. The above (last line) is more-or-less equivalent to:
my @foo; foreach (@a) { push @foo,$_ if ($_ eq "q"); } print scalar @foo;
HTH.

Originally posted as a Categorized Answer.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://183443]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2024-04-18 15:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found