|No such thing as a small change|
Checking a string's presence within an array.by antirice (Priest)
|on May 16, 2003 at 17:56 UTC||Need Help??|
antirice has asked for the
wisdom of the Perl Monks concerning the following question:
Ok, I don't want to beat a dead horse but I've been wondering about this for quite some time now. Suppose you want to see whether or not 'c' is in (a .. z). Of course, I want general case (where the array may contain words instead of letters). What method would you employ to have the program say, "yes, c is a letter that would exist within that array you just created there." Some of the methods I have seen are included in the readmore.
Create a hash and just check for existence (I usually use this):I am just curious which methods people use for this very common problem and which is the most popular. If there are particular cases where you use one method over another, please cite them and explain why...if you don't mind of course :-)
Binary search (not complex enough to justify requiring Search::Binary but very similar parameters passed, just in case):
Regex hard-coded (seen this used extensively twice before):
Introduce quantum theory?