O'Reilly logo

Games, Diversions & Perl Culture by Jon Orwant

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required