in reply to Regex - Matching prefixes of a word
But if there's a limited number of commands a player can give, I would pre-calculate all unique prefixes, store them in a hash (with the real word as value), and then just do the hash access. For instance:my ($first) = /^\s*(\w+)/ or next; if (index $first, "hello") { ... whatever ... }
my %prefixes = calc_all_unique_prefixes; if (/my ($first) = /^\s*(\w+)/) { if (exists $prefixes{$first}) { do_command $prefixes{$first} } else { print "What?\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regex - Matching prefixes of a word
by SuicideJunkie (Vicar) on Jul 24, 2009 at 17:23 UTC |