donna writes:
> There is the Text::Ispell module from CPAN.
>
> If you have a dictionary file (like /usr/dict/words under UNIX) it is easy
> to
> write a simple misspelling-detector in perl:
>
>
> my %dict;
> open D,"</usr/dict/words";
> while(<D>){
> chomp;
> $dict{lc($_)}=1;
> }
> close D;
>
> my $text='Is there anyway to write a spell checker in perl?? Please
> help.';
> my @words=split /[^a-zA-Z0-9']+/,$text;
> foreach (@words){
> if(!defined $dict{lc($_)}){
> print "\"$_\" is not in the dictionary\n";
> }
> }
>
> granted this isn't the most efficient piece of code (i shudder to think
> about
> what might happen if the dictionary file is large...). let's call it an
> exercise for the reader, eh? :-) - d
By comparison, to accomplish the same thing in 30-year-old BASIC, using the
25-year-old IMAGE database that I just referenced requires this much code:
CALL XDBGET(B$,"MASTERSET;",M5,S[*],"WORD;",W$,"")
That's it. Just stick that line in anywhere in your code. If S[1] = 0, the
word is spelled correctly. If not, it's not. But even more than that, it's
also really quite efficient.
Wirt Atmar
* To join/leave the list, search archives, change list settings, *
* etc., please visit http://raven.utc.edu/archives/hp3000-l.html *
|