Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Answer: How to find out if X is an element in an array?

by rajib (Novice)
on Aug 20, 2002 at 17:31 UTC ( #191525=categorized answer: print w/replies, xml ) Need Help??

Q&A > arrays > How to find out if X is an element in an array? - Answer contributed by rajib

$X = "x"; @array = ("y", "z", "x"); $i = 0; while (($i <= $#array && ($array[$i] ne $X)) { ++$i; } if ($i <= $#array) { # searched it & eureka return 1; # for true; } return 0; # for false;

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2020-10-27 16:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (257 votes). Check out past polls.

    Notices?