Chapter 20. Surreal HTML

Lincoln D. Stein

If you’ve poked around the eg directory in old Perl distributions, you might have noticed a small program called travesty. This program takes any regular text file, processes it, and spews out a curious parody of the original. For example, here’s a small part of what you get when you feed it this article:

Travesty achieves this by calling the Perl distribution's eg
directory, you may have noticed a small program called travesty. This
program takes any regular text file, processes it, and spews out a
curious parody of the number of words to generate (lines 81 to
82). Travesty::regurgitate returns a parse tree in turn, calling
ref to determine whether the node is any of the tree by returning a
value of 0 from the LWP modules, as well as back to Mangler's fill-out
form.

Travesty’s output is almost, but not quite, English. Reasonable phrases and sometimes whole sentences pop out, but the whole makes no sense at all. However, if you were to analyze the word frequency of the output, you’d find it identical to the original. Furthermore, if you were to count the frequency of word pairs, you’d find them the same as well. Travesty achieves this by using the original text to create a lookup table of word triples (A,B,C), in which C is indexed on the (A,B) pair. After creating this table, it spews out a parody of the text using a Markov chain: the program chooses a random (A,B) pair and uses the lookup table to pick a C. The new (B,C) pair is now used ...

Get Web, Graphics & Perl/Tk Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.