This program is a re-written CGI version of Travesty, which is featured in Programming Perl and was first published in Byte in 1984 or 1985 (a Pascal version). The Programming Perl version never seemed to work right... this version rules and produces hysterically garbled output in the style of the input, regardless of what language it's written in.
#!/usr/bin/perl $debug = 0; use CGI qw/:standard :netscape :html3/; use CGI::Carp 'fatalsToBrowser'; $text = param('text'); $order = param('order'); $textlen = substr(length($text),0,64000); srand(time||$$); randomize; $absmaxsent = 4; $maxsent = int(rand()*$absmaxsent+2); $text =~ s/[^A-z\.\,\;\-\n\'\ \?\"0-9\$\:]//g; $text =~ s/\n/ /g; while ($text =~ s/\s\s/ /g) {}; for ($i=0; $i<(length($text)-$order); $i++) { $key = substr($text, $i, $order); $key =~ s/ /}/g; push(@{$options{$key}},substr($text,$i+$order,1)); } print header(-expires=>'now'); print "<BODY BGCOLOR=FFFFFF>"; if ($debug) { print "<hr>Key options defined:<p><table width=600>"; foreach (sort keys %options) { @keyoptions = @{$options{$_}}; $maxoption = $#keyoptions + 1; $newchar = @keyoptions[int(rand()*$maxoption)]; print "<tr><td><b>$_</b>&nbsp;[$maxoption, $newchar]</td><td>@ke +yoptions</td></tr>\n"; } print "</table><p><hr>"; } $window = substr($text,0,$order); $output = $window; $srcwindow = $window; while(1) { $window =~ s/ /}/g; if (!exists($options{$window})) { $output .= ". $srcwindow"; $window = $srcwindow; next; } else { @keyoptions = @{$options{$window}}; $maxoption = $#keyoptions + 1; $newchar = @keyoptions[int(rand()*$maxoption)]; $output .= $newchar; } $scount++ if (substr($output,length($output)-2) eq ". "); if ($scount>=$maxsent) { $output .= "<p>\n"; $maxsent = int((rand()*$absmaxsent)+1); $scount = 0; last if (length($output)>$textlen); } $window = substr($window,1) . $newchar; last if $iterations++>32000; } $outlen = length($output); print qq{ <table width=580><tr><td> $output <hr> <i>$iterations iterations, $outlen output length, $textlen input lengt +h. © 2000 David C. Troy, dave@toad.net</i> </td></tr></table> };

In reply to Travesty -- done properly by Anonymous Monk

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.