Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Spell checker

by pingo (Hermit)
on Dec 22, 2004 at 13:03 UTC ( #416767=CUFP: print w/replies, xml ) Need Help??

Here is a silly little thing that will attempt to correct misspelled code. I have intentionally left out a few things (unlink and system, for example) to make it somewhat less dangerous to use, but still, if you use this in a production environment you are mad. :-)

package Speller; use strict; use Filter::Simple; use String::Similarity; my %known; @known{qw(abs accept alarm and ARGV atan2 BEGIN bind binmode bless cal +ler chdir chmod chomp chop chown chr chroot close closedir cmp connec +t continue cos crypt dbmclose dbmopen defined delete die do dump each + else elsif END ENV eof eq eval exists exit exp EXPORT EXPORT_OK fcnt +l fileno flock for foreach fork format formline ge getc getlogin getp +eername getpgrp getppid getpriority getsockname getsockopt glob gmtim +e goto grep gt hex HOME if import INC index int ioctl ISA join keys k +ill last lc lcfirst le length link listen local localtime lock log ls +tat lt m map mkdir my ne next no not oct open opendir or ord our pack + package pipe pop pos print printf prototype push quotemeta rand read + readdir readline readlink readpipe recv redo ref rename require rese +t return reverse rewinddir rindex rmdir s scalar seek seekdir select +send setpgrp setpriority setsockopt shift shutdown SIG sin sleep sock +et socketpair sort splice split sprintf sqrt srand stat strict study +sub substr symlink syscall sysopen sysread sysseek syswrite tell tell +dir tie tied time times tr truncate uc ucfirst umask undef unless unp +ack unshift untie until use utime values vec wait waitpid wantarray w +arn while write x xor y)} = undef; FILTER_ONLY code => \&filter; sub filter { s/\b(?<![\$@%#])([a-z]\w*)\b/check($1)/eg; } sub check { return $_[0] if exists $known{$_[0]}; my ($limit, $best_choice) = -1; foreach my $known (keys %known) { my $similarity = similarity $_[0], $known, $limit; if ($similarity > $limit) { $best_choice = $known; $limit = $similarity; } } return $best_choice; } 1;

And here is a small example script:

#!/usr/bin/perl -w use Speller; yuse struct; mey @words = qw(samtsirhc yrreM); fer (moy $i = $#words; $i >= 0; $i--) { omy $x = reverb($words[$i]); pronto $x, ' '; } prunt "\n";

Replies are listed 'Best First'.
Re: Spell checker
by Aristotle (Chancellor) on Dec 22, 2004 at 16:34 UTC

    ROFL. This deserves a place on CPAN — Acme::SpellCheck, anyone?

    Makeshifts last the longest.

Re: Spell checker
by zentara (Archbishop) on Dec 22, 2004 at 18:11 UTC
    I use Perl's built-in spell checking:
    Undefined subroutine &main::sleap called at ./sleep line 3.

    I'm not really a human, but I play one on earth. flash japh
Re: Spell checker
by DrHyde (Prior) on Dec 25, 2004 at 00:00 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://416767]
Approved by silent11
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2020-12-01 21:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you use taint mode?





    Results (20 votes). Check out past polls.

    Notices?