Chapter 38. Searching for Rhymes with Perl
La poésie doit être faite par tous.
Poetry is for everyone to make.
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 ...
Get Games, Diversions & Perl Culture 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.