in reply to Better way to search array for elements in other array?
In other words, take the smaller of the two lists and turn it into a single regular expression. This turns your algorithm from O(N * M) to O(N). If this still doesn't make sense, please let me know and I will provide a working example that you can tweak to see if it fits your needs.
Update: The code snippet if (index(lc($data),lc($string)) ge 0) { should likely just be if (index($lc_data, $lc_string) > -1) {. First, you should use > instead of ge when dealing with numerical values (see perlop). Second, repeatedly lowercasing the values is wasted time. Do it once and then compare the copy.
Cheers - L~R
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Better way to search array for elements in other array?
by tilly (Archbishop) on Jan 24, 2011 at 20:10 UTC | |
by Limbic~Region (Chancellor) on Jan 24, 2011 at 20:20 UTC | |
|
Re^2: Better way to search array for elements in other array?
by ikegami (Patriarch) on Jan 24, 2011 at 20:37 UTC | |
by Limbic~Region (Chancellor) on Jan 24, 2011 at 21:30 UTC | |
by ikegami (Patriarch) on Jan 24, 2011 at 23:07 UTC | |
by Limbic~Region (Chancellor) on Jan 24, 2011 at 23:23 UTC | |
by ikegami (Patriarch) on Jan 25, 2011 at 04:10 UTC |