Created
January 20, 2012 13:06
-
-
Save ismaild/1647325 to your computer and use it in GitHub Desktop.
Soundex Perl Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| sub soundex | |
| { | |
| local (@s, $f, $fc, $_) = @_; | |
| push @s, '' unless @s; # handle no args as a single empty string | |
| foreach (@s) | |
| { | |
| tr/a-z/A-Z/; | |
| tr/A-Z//cd; | |
| if ($_ eq '') | |
| { | |
| $_ = $soundex_nocode; | |
| } | |
| else | |
| { | |
| ($f) = /^(.)/; | |
| tr/AEHIOUWYBFPVCGJKQSXZDTLMNR/00000000111122222222334556/; | |
| ($fc) = /^(.)/; | |
| s/^$fc+//; | |
| tr///cs; | |
| tr/0//d; | |
| $_ = $f . $_ . '000'; | |
| s/^(.{4}).*/$1/; | |
| } | |
| } | |
| wantarray ? @s : shift @s; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment