Skip to content

Instantly share code, notes, and snippets.

@ismaild
Created January 20, 2012 13:06
Show Gist options
  • Save ismaild/1647325 to your computer and use it in GitHub Desktop.
Save ismaild/1647325 to your computer and use it in GitHub Desktop.
Soundex Perl Example
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