giulienk has asked for the wisdom of the Perl Monks concerning the following question:
I need to work out a bunch of data with an algorithm i didn't choose. The algorithm has nothing to do with the "real" soundex algorithm (see Text::Soundex), even though it was called like that where i read it. So from now on i will baptize this algorithm Weirdex; this is described to receive a string in input and then:
- Strip chars outside [a-zA-Z] range
- Take all consonants except doubles (that should be reduced to one)
- Take just the first vowel
Examples:
Original | Weirdex |
---|---|
giulienk | gilnk |
larry wall | larywl |
etheroskedasticity | ethrskdstcty |
My first coding of Weirdex is
sub weirdex { local $_ = shift; my ($weirdex, $vowel) = ('', 0); s/[^a-zA-Z]//g; for (split '') { if (/[aeiou]/i) { $vowel++ or $weirdex .= $_; } else { $weirdex .= $_ if substr($weirdex, -1, 1) ne $_; } } return $weirdex; }
I'm interested in more elegant/efficient solutions, only regexp solutions and even Golf/Obfu ones.
Thank you.
$|=$_="1g2i1u1l2i4e2n0k",map{print"\7",chop;select$,,$,,$,,$_/7}m{..}g
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Weird "soundex" algorithm
by broquaint (Abbot) on Aug 28, 2003 at 15:17 UTC | |
by giulienk (Curate) on Aug 28, 2003 at 15:32 UTC | |
by diotalevi (Canon) on Aug 28, 2003 at 19:10 UTC | |
by broquaint (Abbot) on Aug 28, 2003 at 23:58 UTC | |
by diotalevi (Canon) on Aug 29, 2003 at 01:53 UTC | |
Re: Weird "soundex" algorithm
by jmcnamara (Monsignor) on Aug 28, 2003 at 15:20 UTC | |
Re: Weird "soundex" algorithm
by rcaputo (Chaplain) on Aug 28, 2003 at 15:46 UTC | |
Re: Weird "soundex" algorithm
by Aristotle (Chancellor) on Aug 28, 2003 at 16:03 UTC | |
Re: Weird "soundex" algorithm
by Anonymous Monk on Aug 28, 2003 at 15:37 UTC | |
by broquaint (Abbot) on Aug 28, 2003 at 15:51 UTC | |
by PhilHibbs (Hermit) on Aug 29, 2003 at 12:15 UTC | |
Re: Weird "soundex" algorithm
by giulienk (Curate) on Sep 01, 2003 at 06:56 UTC |
Back to
Seekers of Perl Wisdom