Which is all well and good. For the most part, it works beautifully. The problem is that some phonemes in IPA are represented with two symbols (for example, ʣ), and perl is treating these as separate characters when calculating the edit distance.

I've just tested Text::Levenshtein::Damerau with the ʣ digraph, and it treats it as a single character:

use lib 'lib'; use strict; use warnings; use 5.010; use Text::Levenshtein::Damerau qw/edistance/; use charnames ":full"; use utf8; say edistance("e\N{LATIN SMALL LETTER DZ DIGRAPH}gar", 'edgar'); # output: 1

So the problem seems to be that you don't pass properly decoded strings to edistance

Is unicode the best way to do this? Are there any easier ideas that I am simply missing? Do I have to "use Encode"? I have seen some sample scripts that use it, and others that don't.

Unicode is the best way to do this, yes.

If your data comes in as a byte string, yes, you'll need use Encode and decode the data before passing it to edistance. And yes, some scripts use it, and others not, because not all example scripts do the same thing in the same way.

I hope this article answers some of your questions. In the end you'll just have to learn about character encodings and how perl handles them, and then fix your problem with that knowledge.


In reply to Re: Reading IPA characters in Perl (Unicode?) by moritz
in thread Reading IPA characters in Perl (Unicode?) by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.