#!/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 anti around as at before behind below beneath beside besides between beyond but 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 ($string_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); }