1Text::Soundex(3pm) Perl Programmers Reference Guide Text::Soundex(3pm)
2
3
4
6 Text::Soundex - Implementation of the Soundex Algorithm as Described by
7 Knuth
8
10 use Text::Soundex;
11
12 $code = soundex $string; # get soundex code for a string
13 @codes = soundex @list; # get list of codes for list of strings
14
15 # set value to be returned for strings without soundex code
16
17 $soundex_nocode = 'Z000';
18
20 This module implements the soundex algorithm as described by Donald
21 Knuth in Volume 3 of The Art of Computer Programming. The algorithm is
22 intended to hash words (in particular surnames) into a small space
23 using a simple model which approximates the sound of the word when spo‐
24 ken by an English speaker. Each word is reduced to a four character
25 string, the first character being an upper case letter and the remain‐
26 ing three being digits.
27
28 If there is no soundex code representation for a string then the value
29 of $soundex_nocode is returned. This is initially set to "undef", but
30 many people seem to prefer an unlikely value like "Z000" (how unlikely
31 this is depends on the data set being dealt with.) Any value can be
32 assigned to $soundex_nocode.
33
34 In scalar context "soundex" returns the soundex code of its first argu‐
35 ment, and in list context a list is returned in which each element is
36 the soundex code for the corresponding argument passed to "soundex"
37 e.g.
38
39 @codes = soundex qw(Mike Stok);
40
41 leaves @codes containing "('M200', 'S320')".
42
44 Knuth's examples of various names and the soundex codes they map to are
45 listed below:
46
47 Euler, Ellery -> E460
48 Gauss, Ghosh -> G200
49 Hilbert, Heilbronn -> H416
50 Knuth, Kant -> K530
51 Lloyd, Ladd -> L300
52 Lukasiewicz, Lissajous -> L222
53
54 so:
55
56 $code = soundex 'Knuth'; # $code contains 'K530'
57 @list = soundex qw(Lloyd Gauss); # @list contains 'L300', 'G200'
58
60 As the soundex algorithm was originally used a long time ago in the US
61 it considers only the English alphabet and pronunciation.
62
63 As it is mapping a large space (arbitrary length strings) onto a small
64 space (single letter plus 3 digits) no inference can be made about the
65 similarity of two strings which end up with the same soundex code. For
66 example, both "Hilbert" and "Heilbronn" end up with a soundex code of
67 "H416".
68
70 This code was implemented by Mike Stok ("stok@cybercom.net") from the
71 description given by Knuth. Ian Phillipps ("ian@pipex.net") and Rich
72 Pinder ("rpinder@hsc.usc.edu") supplied ideas and spotted mistakes.
73
74
75
76perl v5.8.8 2001-09-21 Text::Soundex(3pm)