Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
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 :-)
Linear search:
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?
antirice In reply to Checking a string's presence within an array. by antirice
|
|