Current Issue


Table of contents

CD-ROM

Sys Admin and The Perl Journal CD-ROM version 12.0

Version 12.0 delivers every issue of Sys Admin from 1992 through 2006 and every
issue of The Perl Journal from 1996-2002 in one convenient CD-ROM!

Order now!

Sys Admin Magazine > Archives > 1999 > 9912

Figuring Phone-y Words

Randal L. Schwartz

Every day, we seem barraged with phone numbers that “spell” things, like “please dial 1-ZZZ-HE-MUST-PAY to force your older brother to pay for the call!”. That's because since nearly day one of dial phone service (back when it was really a dial), we've had these letters that go along with each of the digits.

On one of the many mailing lists I follow, a question came up the other day: someone wanted to know if there were any large sets of words that all collided to the same number. I thought that'd be a perfect job for Perl, and in a short time, came up with a quick program to scan through the standard UNIX dictionary in /usr/dict/words to find the longest such collision list (or lists, if more than one). Since the program illustrates some basic data reduction techniques, I thought I'd pass it along to you as well.

First, comes the most critical part. Given an arbitrary string, like “merlyn”, what are the digits used to construct that? Well, we need to know that m is 6, and e is 3, and so on. Now, there are many slow ways to do this, but the fastest way is a tr operator:

$_ = "merlyn";
tr[abcdefghijklmnoprstuvwxy]
  [222333444555666777888999];
print;

which prints 637596. Here, I've used the feature that permits tr operands to be delimited with arbitrary balancing punctuation, together with the optional whitespace that can be between the old list and the new list when we use such delimiters. This gives a nice visual layout to let me verify that I've got the right characters with the right translation.




MarketPlace

FREE Trial Download Speeds Up Systems Now!
New Diskeeper 2008 Maximizes System Performance and Reliability�Automatically!

Online Crash Analysis
Automatically capture customer crash data, no debugger required. Support for .NET, C++, OS X, Java.

Discover WinDev 12 RAD
and develop 10 times faster ! ALM, IDE, .Net, PDF, 5GL, Database, 64-bit, etc. Free Express version

Flowcharts from C/C++ code -- Free trial download
Understand C/C++ code in less time. A new team member ? Inherited legacy code ? Get up to speed faster with Crystal Flow for C/C++. Code-formatting improves readability. Flowcharts are integrated with code browser. Export flowcharts to Visio.

Wanna see your ad here?