http://www.perlmonks.org?node_id=1017027

I was digging around some old scripts in my play directory and found a script I started writing for form inputs for my site. It checks for eight little grammar problems or typographical errors, some of which I am guilty of every so often. If you can think of any more which would fit the format, please let me know.

You can take out WORDLIST and just use join if you do not feel like installing Lingua::EN::Inflect (my favorite module). If you do not want to use the last until, just take out the returns in correct_grammar.

I do not know how cool this is, but I think it is a bit cute.

#!/usr/bin/perl use strict; use warnings; use Lingua::EN::Inflect qw(WORDLIST); local $\ = "\n"; print "Enter string: "; my $string = <>; chomp($string); my @conjunctions_list = qw(and but or nor); my @prepositions_list = qw( aboard about above across after against along amid among an +ti around as at before behind below beneath beside besides between beyond bu +t by concerning considering despite down during except excepting excluding following for from in inside into like minus near of off on onto opposite outside over past per plus regarding round save since than through to toward towards under underneath unlike until up upon versus via with within without ); sub correct_grammar { my ($string_to_check) = shift; my $CAPS = join('|',"A".."Z"); my $conjunctions = join('|',@conjunctions_list); my $prepositions = join('|',@prepositions_list); my @errors; push @errors, "have not used punctuation" if ($string_to_check +!~ /(?:\.|\!|\?|\,|\;)/); push @errors, "have not spaced your words out" if ($string_to_check +!~ /\s/); push @errors, "have not capitalized anything" if ($string_to_check +!~ /(?:$CAPS)/); push @errors, "have two capital letters in a row in your text" if ($ +string_to_check =~ /(?:$CAPS)(?:$CAPS)/); push @errors, "started with a conjunction" if ($string_to_check +=~ /^(?:$conjunctions) /i); push @errors, "ended with a preposition" if ($string_to_check +=~ / (?:$prepositions)(|\W)$/i); push @errors, "have a number which should be written out" if ($strin +g_to_check =~ / \d\d /); push @errors, "misspelled 'the'" if ($string_to_check +=~ / teh /i); if (scalar(@errors) > 0) { print "It appears you ".WORDLIST(@errors,{conj => 'and'}).'.'; return 0; } else { print "Good job, and thank you!"; return 1; } } until (correct_grammar($string)) { $string = <>; chomp($string); }

Have fun with it!

Have a cookie and a very nice day!
Lady Aleena