Don't ask to ask, just ask | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
If it's just a one-time check, or if the array changes frequently, it's probably not all that efficient to suck the whole thing into a hash just to do three exists tests. Converting the big set to a hash is an O(n) operation, but a computationally more expensive one than the O(n) operation of grepping for the thee elements.
This method uses a small three-element hash as the lookup list. Each time an entry is found, it is deleted from the lookup hash so that you assure that all three items are found (as opposed to the same item three times). If the big array changes infrequently, and you will be doing more than a few lookups on it, then it makes sense to convert the big array to a hash and invert the search:
Dave In reply to Re: Check Array Elements
by davido
|
|