in reply to Fast wordlist lookup for game
A hash seems reasonable to use at that dictionary size. 50k is nothing.
Nevertheless, if you're still concerned, I suggest you use grep with eq on the list of words, rather than trying to match a pattern against a long string. That is going to be a lot more efficient.
Something like this:
And then you check using something like:my %word; open my $fh, "<", "/usr/dict/words"; chomp, push @{$word{substr $_, 0, 1}}, $_ while <$fh>; close $fh;
If you want to ignore case, you'd just useif(grep $_ eq $user_input, @{$word{substr $user_input, 0, 1} || []}) { # it's there } else { # no, that wasn't it }
respectively.chomp, $_ = lc, push @{$word{substr($_, 0, 1)}}, $_ while <$fh>; # and grep lc eq $user_input, @{$word{substr($user_input, 0, 1)} || []}
Makeshifts last the longest.
|
|---|