perlfunc
root
<P>
Text::Soundex - Implementation of the Soundex Algorithm as Described by
Knuth
<P>
<HR>
<P>
<PRE> use Text::Soundex;
</PRE>
<P>
<PRE> $code = soundex $string; # get soundex code for a string
@codes = soundex @list; # get list of codes for list of strings
</PRE>
<P>
<PRE> # set value to be returned for strings wit
<P>
This module implements the soundex algorithm as described by Donald Knuth
in Volume 3 of <STRONG>The Art of Computer Programming</STRONG>. The algorithm is intended to hash words (in particular surnames) into a
small space using a simple model which approximates the sound of the word
when spoken by an English speaker. Each word is reduced to a four character
string, the first character being an upper case letter and the remaining
three being digits.
<P>
If there is no soundex code representation for a string then the value of
<CODE>$soundex_nocode</CODE> is returned. This is initially set to [perlfunc:undef|undef], but many people seem to prefer an <EM>unlikely</EM> value like <CODE>Z000</CODE>
(how unlikely this is depends on the data set being dealt with.) Any value
can be assigned to <CODE>$soundex_nocode</CODE>.
<P>
In scalar context <CODE>soundex</CODE> returns the soundex code of its first argument, and in array context a list
is returned in which each element is the soundex code for the corresponding
argument passed to <CODE>soundex</CODE> e.g.
<P>
<PRE> @codes = soundex qw(Mike Stok);
</PRE>
<P>
leaves <CODE>@codes</CODE> containing <CODE>('M200', 'S320')</CODE>.
<P>
<HR>
<H1><A NAME="EXAMPLES">EXAMPLES</A></H1>
<P>
Knuth's examples of various names and the soundex codes they map to are
listed below:
<P>
<PRE> Euler, Ellery -> E460
Gauss, Ghosh -> G200
Hilbert, Heilbronn -> H416
Knuth, Kant -> K530
Lloyd, Ladd -> L300
Lukasiewicz, Lissajous -> L222
</PRE>
<P>
so:
<P>
<PRE> $code = soundex 'Knuth'; # $code contains 'K530'
@list = soundex qw(Lloyd Gauss); # @list contains 'L300', 'G200'
</PRE>
<P>
<HR>
<H1><A NAME="LIMITATIONS">LIMITATIONS</A></H1>
<P>
As the soundex algorithm was originally used a <STRONG>long</STRONG> time ago in the
<FONT SIZE=-1>US</FONT> it considers only the English alphabet and
pronunciation.
<P>
As it is mapping a large space (arbitrary length strings) onto a small
space (single letter plus 3 digits) no inference can be made about the
similarity of two strings which end up with the same soundex code. For
example, both <CODE>Hilbert</CODE> and <CODE>Heilbronn</CODE> end up with a soundex code of <CODE>H416</CODE>.
<P>
<HR>
<H1><A NAME="AUTHOR">AUTHOR</A></H1>
<P>
This code was implemented by Mike Stok (<CODE>stok@cybercom.net</CODE>) from the description given by Knuth. Ian Phillips (<CODE>ian@pipex.net</CODE>) and Rich Pinder (<CODE>rpinder@hsc.usc.edu</CODE>) supplied ideas and spotted mistakes.
<HR>