Games, Diversions & Perl Culture: Best of the Perl Journal and over 2 million other books are available for Amazon Kindle . Learn more

Sign in to turn on 1-Click ordering.
Trade in Yours
For a £1.38 Gift Card
Trade in
More Buying Choices
Have one to sell? Sell yours here
Sorry, this item is not available in
Image not available for
Image not available

Start reading Games, Diversions & Perl Culture: Best of the Perl Journal on your Kindle in under a minute.

Don't have a Kindle? Get your Kindle here, or download a FREE Kindle Reading App.

Games, Diversions & Perl Culture: Best of the Perl Journal (Best of the Perl Journal Series) [Paperback]

Jon Orwant

Price: £32.50 & FREE Delivery in the UK. Details
o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o
Only 1 left in stock (more on the way).
Dispatched from and sold by Amazon. Gift-wrap available.
Want it Tuesday, 23 Sep.? Choose Express delivery at checkout. Details


Amazon Price New from Used from
Kindle Edition £24.71  
Paperback £32.50  
Trade In this Item for up to £1.38
Trade in Games, Diversions & Perl Culture: Best of the Perl Journal (Best of the Perl Journal Series) for an Amazon Gift Card of up to £1.38, which you can then spend on millions of items across the site. Trade-in values may vary (terms apply). Learn more

Book Description

1 Jun 2003 0596003129 978-0596003128 1

The Perl Journal (TPJ) did something most print journals aspire to, but few succeed. Within a remarkable short time, TPJ acquired a cult-following and became the voice of the Perl community. Every serious Perl programmer subscribed to it, and every notable Perl guru jumped at the opportunity to write for it. Back issues were swapped like trading cards. No longer in print format, TPJ remains the quintessential spirit of Perl--a publication for and by Perl programmers who see fun and beauty in an admittedly quirky little language.Games, Diversions, and Perl Culture is the third volume of The Best of the Perl Journal, compiled and re-edited by the original editor and publisher of The Perl Journal, Jon Orwant. In this series, we've taken the very best (and still relevant) articles published in TPJ over its 5 years of publication and immortalized them into three volumes.The 47 articles included in this volume are simply some of the best Perl articles ever written on the subjects of games, diversions, and the unique culture of this close-knit community, by some of the best Perl authors and coders. Games, Diversions & Perl Culture focuses on entertaining topics that make Perl users such fanatics about the language. You'll find all of the playful features TPJ offered over the years, including the Obfuscated Perl Contests, Perl Quiz Shows, humor articles, and renowned one-line recipes. The book also contains a panoply of quirky applications of Perl, including genetic algorithms, home automation, music programming, and an entire section on natural language processing.This anthology is an unmatched compendium of Perl lore.

Frequently Bought Together

Games, Diversions & Perl Culture: Best of the Perl Journal (Best of the Perl Journal Series) + Perl & LWP
Price For Both: £58.49

Buy the selected items together
  • Perl & LWP £25.99

Customers Who Bought This Item Also Bought

Product details

More About the Author

Discover books, learn about writers, and more.

Product Description

About the Author

Jon Orwant, a well-known member of the Perl community, founded The Perl Journal and co-authored O'Reilly's bestseller, Programming Perl, 3rd Edition

Excerpt. © Reprinted by permission. All rights reserved.

CHAPTER 38 - Searching for Rhymes with Perl

Sean M. Burke

La poésie doit être faite par tous.
Poetry is for everyone to make.
—Lautréamont (Isidore Ducasse, 1846–1870)

Wherever I go, people always come up to me and say "Sean, you gotta help me—I need to find a three-syllable word that rhymes with toad." And my answer is always the same; I always say "Well, we’re going to have to pull out the Perl for this one!"

Because, while TPJ articles constantly demonstrate that Perl is good at everything from designing sundials to peppering IRC with Eliza bots, one thing that it’s really good at is making short little programs for searching text. And that’s what this article is about—how to search text (specifically wordlists or pronunciation databases) for rhymes of various kinds.

Where to Look
If this article were about rhyming in Spanish, Italian, or Finnish, it’d be a whole lot shorter! Because for the most part, the way something is spelled in these languages tells you pretty well how to pronounce it; ending with the same letters may not be exactly the same thing as rhyming, but often you can start with the spelling and apply some trivial string replacement operations to get a phonetic form that can be searched for the presence of a rhyme. This can work even with French, where (for the most part) spelling tells you pronunciation, even though the pronunciation won’t tell you the spelling.

However, English isn’t that kind of language—not only does the English pronunciation of a word not tell you how to spell it, its spelling doesn’t tell you how to pronounce it. But luckily, lexicons exist that are basically simple databases, associating the normal written form of a word with some representation of its pronunciation. One of my favorite lexicons (partly because it’s free!) is Moby Pronunciator. It consists of about 177,000 entries, one word to a line, that look like this:
accipitrine /&/k's/I/p/I/tr/I/n
Accius '/&/k/S//i//@/s
acclaim /@/'kl/eI/m
acclamation ,/&/kl/@/'m/eI//S//@/n
acclamation_medal ,/&/kl/@/'m/eI//S//@/n_'m/E/d/-/l
acclamatory /@/'kl/&/m/@/,t/oU/r/i/
acclimate /@/'kl/aI/m/I/t
acclimation ,/&/kl/@/'m/eI//S//@/n
acclimation_fever ,/&/kl/@/'m/eI//S//@/n_'f/i/v/@/r
acclimatise /@/'kl/aI/m/@/,t/aI/z
acclimatize /@/'kl/aI/m/@/,t/aI/z
acclivity /@/'kl/I/v/I/t/i/
Ignoring the meanings of these symbols, you can see that (as the README will tell you), the format of each line is the word (or underscore-separated multiword phrase, like "acclamation_medal"), then a space, then the phonetic notation. What the slashes mean (and why there isn’t one between the /k/ and /l/) is something I’m unsure of. But I am sure that these slashes are annoying, since they get in the way of me trying to search. I have to remember to stick them in my search patterns, and I always worry that I stuck in one too many. The same goes for the commas and apostrophes, which indicate stress—and when I’m looking for a rhyme, I may not care about stress.

Preparing the Data
So the first thing to do, whether it’s for the Moby Pronunciator wordlist or for any other wordlist you choose, is to strip out the parts you don’t want, take what’s left, and format it the way you like. Here, we can do that by deleting certain tokens in the pronunciation part:

• Slashes (used to separate phonemes?)
• Spaces and underscores (used to separate words)
• Apostrophes (used to precede syllables with primary stress)
• Commas (used to precede syllables with secondary stress)
Since these tokens are all single characters, we can delete them by just applying a tr operator to slashes, spaces, underscores, commas, and apostrophes. We use the d switch ("d" for delete):

tr/\/ _,'//d;

Personally, I find it disconcerting to have the backslash-escaped slash in there, so I tend to use different delimiters, like matching angle brackets:


Either way, you can build this into a program that reads the Moby Pronunciator

# mpron_convert -- Turn the mobypron.unc program into the mpron.dat
# format that we'll use.

use strict;
@ARGV = 'mobypron.unc' unless @ARGV;
my ($word, $pron, $meter, $next_stress_flag);
my $Debug = 0;
# $/ = "\cm"; # May be necessary

open(OUT, ">mpron.dat");

while () {
($word, $pron) = split(' ', $_, 2);
next unless $pron;

$meter = '';
$next_stress_flag = '0';
foreach my $x ($pron =~ mg) {
if ($x eq ',') {
$next_stress_flag = '2'; # secondary stress
} elsif($x eq "'") {
$next_stress_flag = '1'; # primary stress
$meter .= $next_stress_flag;
$next_stress_flag = '0';

# So "stressless" one-syllable words all get stress. Also needed
# for multiword phrases mode of monosyllabic words, like "base_load".
$meter =~ tr/0/2/ if $meter =~ m/^0+$/s;

# Remove stress marks, word separators, and the mystery slashes

$pron =~ trd;

sleep(0), printf "%10s %-20s %s\n", $meter, $word, $pron if $Debug;
print OUT join("\t", $word, $meter, $pron), "\n";
last if $Debug and $. > 1000;

Now, to search this database for rhymes (or any other phonetic information), there are two ways to go about it: use the code above, and once you’ve modified $pron, search it for a pattern; or write $word and the modified $pron to a file, and then grep that file.

The benefit of the former is simplicity, but the benefit of the latter is efficiency—no need to constantly chomp, split, and tr for each line. Now, normally I say that program (as opposed to programmer) efficiency is overvalued in programming. But in this case, the Moby wordlist is so very large that the waste of the first approach is significant.

Inside This Book (Learn More)
Browse Sample Pages
Front Cover | Copyright | Table of Contents | Excerpt | Index | Back Cover
Search inside this book:

Customer Reviews

There are no customer reviews yet on
5 star
4 star
3 star
2 star
1 star
Most Helpful Customer Reviews on (beta) 3.7 out of 5 stars  3 reviews
1 of 2 people found the following review helpful
4.0 out of 5 stars Some jewels and a lot of fluff 7 Mar 2004
By Jack D. Herrington - Published on
This is a tome at 600 pages. But at 48 chapters each one is really small. This is because the book is actually a set of articles. Some of the articles are fantastic and very helpful. Specifically between 18 and 23, which cover text handling for stuff like smart searching and internationalization. Other chapters, like 37, which is about Perl Haikus, are really for the hardcore Perl lover.
For the average Perl user, check it out to make sure that you are getting the content you need. For the hardcore, you were going to by this book anyway, so why are you reading reviews. ;-)
0 of 1 people found the following review helpful
5.0 out of 5 stars Casual & fun 26 Jan 2004
By Portnoy Huston - Published on
This book is a grab bag of fun Perl uses. The obfuscated Perl contests are completely mind-bending - it's amazing what people can do with this language. The games material is a little light, but overall a good read.
11 of 21 people found the following review helpful
2.0 out of 5 stars High on "Diversions", Low on "Games" 12 July 2003
By James Edward Gray II - Published on
Format:Paperback|Verified Purchase
First let me state that, as with most O'Reilly books, there is nothing wrong with the writing in here. Topic coverage at least goes deep enough on each article to let you decide if you want to go any further on your own. Some articles mearly cover CPAN module and there are better places to get that kind of material, I think. Coverage of Obfuscation is pretty substantial, if you enjoy that sort of thing (I don't). Still the articles themselves are solid.
Unfortunately, I didn't really enjoy the book, in spite of the above. Honestly, I think it's the title. I'm a big gamer who plays pretty much everything and I bought this book expecting to get some gaming content for my favorite programming language. (Note the first word of the title, "Games".) If that's what your looking for too, look on, it's not here. The book has four chapters covering game related material. The first mainly covers the game tool modules available from CPAN and that is sadly slim pickins. The second describes a contest the Perl Journal held and was one of my two favorite chapters in the whole book. The third is all about the Perl Z-Machine "rezrov", which is at least a little informative. The fourth is How to Build a TK Card Game. That's it, for gaming material, be warned.
The book mainly focuses on random aspects of linguistic theory, including NPL. If that's what you're after, this is the book for you.
Were these reviews helpful?   Let us know

Customer Discussions

This product's forum
Discussion Replies Latest Post
No discussions yet

Ask questions, Share opinions, Gain insight
Start a new discussion
First post:
Prompts for sign-in

Search Customer Discussions
Search all Amazon discussions

Look for similar items by category