keiusui has asked for the wisdom of the Perl Monks concerning the following question:
@s = ('abc', 'dog', 'cat', 'rabbit', 'attic');
and I want to determine if one of the elements of the list is the word 'at'.
'at' is not in the list, although 'cat' and 'attic' are.
In order to search the list, do I have to loop through every element in the list (using the foreach function) until I find a match?
Or, is there a more efficient way of searching a list?
Clearly in my list above, it isn't a hassle to loop through 5 elements in a list. But I'd like to know if there is a more efficient way of searching a list, especially if the list contains hundreds of elements.
Thank you so much!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: searching a list
by davido (Cardinal) on Jun 27, 2006 at 04:34 UTC | |
|
Re: searching a list
by bobf (Monsignor) on Jun 27, 2006 at 04:14 UTC | |
by Limbic~Region (Chancellor) on Jun 27, 2006 at 12:38 UTC | |
|
Re: searching a list
by davidrw (Prior) on Jun 27, 2006 at 04:15 UTC | |
by ikegami (Patriarch) on Jun 27, 2006 at 04:18 UTC | |
by McDarren (Abbot) on Jun 27, 2006 at 04:49 UTC | |
|
Re: searching a list
by Zaxo (Archbishop) on Jun 27, 2006 at 04:17 UTC | |
| |
|
Re: searching a list
by esskar (Deacon) on Jun 27, 2006 at 13:05 UTC |