Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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

In reply to A few grammar checks for strings by Lady_Aleena

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    [Discipulus]: the same for me! I'd use your own one! ;=)

    How do I use this? | Other CB clients
    Other Users?
    Others romping around the Monastery: (9)
    As of 2018-05-28 10:02 GMT
    Find Nodes?
      Voting Booth?