Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Random Bumper Sticker Generator

by Buzzsaw (Novice)
on Sep 27, 2000 at 01:31 UTC ( [id://34116]=perlcraft: print w/replies, xml ) Need Help??

   1: This simple, silly script will generate bumper sticker-like phrases sure to bring a grin.  Enjoy!
   2: <code>
   3: @SUBJ = ("A woman", 
   4:          "My kid", 
   5:          "This car", 
   6:          "A gun", 
   7:          "A baby", 
   8:          "A case of beer");
   9: 
  10: @VERB = ("without a man is like a fish without a bike", 
  11:          "beat up your honor roll student", 
  12:          "will brake for donuts", 
  13:          "doesn't kill people", 
  14:          "on board", 
  15:          "has 24 cans of beer");
  16: 
  17: @END = ("and I vote\.", 
  18:         "when you pry it from my cold, dead fingers\.", 
  19:         "so don't pee in my pool\.", 
  20:         "so get used to it\.", 
  21:         "and my other car is a cadillac\.", 
  22:         "\; coincidence\?");
  23: 
  24: print "$SUBJ[int(rand(6))] $VERB[int(rand(6))] $END[int(rand(6))]\n";
  25: <code>

Replies are listed 'Best First'.
RE: Random Bumper Sticker Generator
by ZZamboni (Curate) on Sep 27, 2000 at 17:49 UTC
    Funny :-)

    As a comment, you don't need the int (being in an index will automatically chop the fractional part), and you can replace the hardcoded lengths so that you can add new elements to the arrays. So the last line becomes:

    print "$SUBJ[rand @SUBJ] $VERB[rand @VERB] $END[rand @END]\n";

    --ZZamboni

Re: Random Bumper Sticker Generator
by ailie (Friar) on Dec 12, 2000 at 02:00 UTC

    Likewise, I have a silly script that creates a Hunter S. Thompson-like insult.

    "That devious knee-crawling bastard!"

    #!/usr/bin/perl -w # # A perl script that generates a Hunter S. Thompson-like invective # use strict; my @LIST1; my @PRON; my @LIST2; my @NOUN; @LIST1 = ("vicious", "rancid", "savage", "fiendish", "filthy", "rotten", "demented", "treacherous", "heinous", "scurvy", "devious", "grisly", "hamwit", "filthy", "foetid", "cheapjack", "hellish" ); @PRON = ("You", "That"); @LIST2 = ("festering", "stinking", "crazed", "deranged", "soul-ripping", "drooling", "rabbit-punching", "knee-crawling", "thieving"); @NOUN = ("bastard", "swine", "pig", "pile of albino warts"); print "$PRON[rand @PRON] $LIST1[rand @LIST1] $LIST2[rand @LIST2] $NO +UN[rand @NOUN]!\n";
RE: Random Bumper Sticker Generator
by TGI (Parson) on Sep 27, 2000 at 22:46 UTC
    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; }
RE: Random Bumper Sticker Generator
by NotProud (Novice) on Oct 09, 2000 at 19:15 UTC
    I like this one. and zzamboni's addition was helpful.
RE: Random Bumper Sticker Generator
by merlyn (Sage) on Sep 27, 2000 at 19:24 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-03-29 06:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found