I wrote a "Timecube Aphorism Generator." If you haven't seen the Timecube, you should check it out.

I'm educated dumb, how about you?
Sample output:

A teacher kills a suicidal child before a dog. A teacher enslaves. A lie evolves simultaneously.
I wrote this a early in my Perl-learning effort, but I'd love comments on my coding style and implementation, if you are willing to offer them. This was before I discovered use strict and -w.
#! /usr/bin/perl # Sentence Maker # Read a Grammar and randomly generate sentences. my %rule; # symbols # ------------------------ # Q - sentence # S Subject # P predicate # N Noun # I Intransitive Verb # T Transitive Verb # A Adjective # D Adverb # R Article (a the an) # E Prepositional Phrase # F Preposition $rule{"Q"}="SP|SPE"; $rule{"S"}="N|RN|RAN|"; $rule{"P"}="I|ID|T|TD|TS"; $rule{"E"}="FRN|FRAN"; $s_map{"N"}=\@noun_list; $s_map{"T"}=\@t_verb_list; $s_map{"I"}=\@i_verb_list; $s_map{"A"}=\@adj_list; $s_map{"D"}=\@adv_list; $s_map{"R"}=\@article_list; $s_map{"F"}=\@prep_list; @noun_list= ( "Timecube", "teacher", "teacher", "God", "dog", "gods", "Gene Ray", "evil", '\'Cube Spirit\'', "Evil", "religion", "word", "lie", "scam", "adult", "child", '"Forbidden Truth"', "Nature\'s Harmonic Simultaneous 4-Day Perpetual Time Cube Creatio +n" ); # ' @t_verb_list= ( "enslaves", "educates", "outlaws", "kills", "teaches", "eats", "lies", "equates", "indicts" ); @i_verb_list= ( "evolves", "rotates", "dies", ); @adv_list= ( "slowly", "quickly", "simultaneously" ); @adj_list= ( "stupid", "retarded", "queer", "4-cornered", "1-corner", "4/16", "suicidal", "evil", "brainwashed", "indoctrinated" ); @article_list= ( "the", "a", ); @prep_list= ( "above", "below", "at", "beyond", "before", "inside", ); srand time; # How many sentences? $num_of_sentences = rand(4)+2; for ($i=1; $i<$num_of_sentences; $i++) { $output = exec_rule("Q"); @word_list = split //, $output; foreach $word (@word_list) { $word = choose_word($word); } $word_list[0]="\u$word_list[0]"; $final .= join " ", @word_list; $final .= ". "; } print $final; # --------------------------------- sub exec_rule { my $input_symbol = shift; my $symbol; my @rules; if (exists $rule{$input_symbol}) # Get list of rules { @rules = split /\|/, $rule{$input_symbol}; } else # Bottoming out condition { return $input_symbol; } # Pick rule my $new_symbols = $rules[rand(@rules)]; # Call exec_rule for each symbol, combine results my @symbol_list = split //, $new_symbols; foreach $symbol (@symbol_list) { $symbol = exec_rule($symbol); } # return results return join( "", @symbol_list) } sub choose_word { my $input_symbol = shift; my $word = ${$s_map{$input_symbol}}[rand(@{$s_map{$input_symbol}}) +]; return $word; }

In reply to RE: Random Bumper Sticker Generator by TGI
in thread Random Bumper Sticker Generator by Buzzsaw

Title:
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, details, 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, summary, 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.