A recent posting by MrCromeDome showed a quick CUFP-type script to generate random silliness, presumably to badger cow-orkers. Being in a refactoring mood, I thought that it might be better if you could describe your "remark" in a text file. This would be used as a template for generating messages, not unlike your typical "mad-lib". Since it's just a text file, it can be edited by mere mortals without fear of compilation errors.

In this file, there would be two kinds of replacements: Automatic, where a word is picked from a list of possibilities, and prompted, where the user has to answer a question. Here's an example which incorporates both types using a very basic tagging system:
When I was walking down the [street|boulevard|avenue] a large [squirrel|frog|lemur|llama] [leaped|jumped|ran|crawled] out and [bit|mauled|chewed|spit at] me! You'd never believe what [Name?] said!
When this is run, you'd see something that looks like this, plus or minus input and random factors:
% perl madlib sample.madlib Name? George Jetson When I was walking down the avenue a large llama jumped out and bit me! You'd never believe what George Jetson said!
If you're probably thinking this is a couple of simple regexes, you're not entirely wrong. However, to spice things up, there's a few "rules" about how the program runs: As food for thought, here's my first take at 159 characters, not including linebreaks to suppress the red plus marks:
select STDERR;$|++;select STDOUT;$_=join('',<>); s#\[([^\]]*\?)\]#print STDERR"$1 ";chomp($i=<STDIN>);$i#ge; s#\[([^\]]*)\]#@f=split(/\|/,$1);$f[rand@f]#ge;print

In reply to (Golf) Mad-Lib Generator by tadman

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.