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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|