Using a hash here means you'll get the keys back in a random order. Which may be ok, but can fall down in two scenarios.
First is if the keys can be subsets. e.g., if one is "key1" and another is "key10". You'll want to make sure you get them in order from longest to shortest. Easy enough to do:
This should be pretty fast. Can take a while for big lists, but then so can the index that we're about to run, so worrying about this O(N ln N) operation seems premature.for my $key ( reverse sort {length $a <=> length $b} ) {
The second failure is if you know that certain strings are more likely than others. So you can manually order the keys based on likelihood. This can really speed up the searches, too, if you're constantly short-circuiting things.
This is why I opted, above, for a list of array refs instead of a hash.
In reply to Re^2: if or switch?
by Tanktalus
in thread if or switch?
by gw1500se
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |