I've been reading a lot these days about unicode because I need to work with characters of the IPA (International Phonetic Alphabet), including diacritics.

Figuring things out in Perl has been quite easy thanks to the good documentation (unlike getting my xterm to display unicode... *gr*), but I'm stuck on one last detail.

In the following minimal example, I want to look up things in a hash, and in some cases, the hash key is one of those "combinings characters" (a "small alpha" with a tilde on top of it). The script works ok for all other keys, but breaks when when a combining character is used as the key. I don't know what to do here. Can anyone help me?

file "test_hash.txt"
d 0 0 a 0 1 ɑ̃ 1 0 s 1 1
file "test_input.txt"
das dɑ̃s
the script itself:
#!/usr/bin/perl use strict; use warnings; binmode(STDOUT, ":utf8"); open HASH, '<:utf8', "test_hash.txt"; my %hash = (); while (my $line=<HASH>) { chomp $line; $line =~ s/^(.*?)\t//; my $key = $1; my @line = split /\s+/, $line; $hash{$key} = \@line; } # foreach my $phoneme (keys %hash) { # print $phoneme . ":"; # my @line = @{ $hash{$phoneme} }; # print join ",", @line; # print "\n"; # } open INPUTFILE, '<:utf8', "test_input.txt";; while (my $entry = <INPUTFILE>) { chomp $entry; print $entry . "\n"; my @word = $entry =~ /(\X)/g; for (my $j=0; $j<@word; $j++) { my $letter = $word[$j]; my $input_features = $hash{$letter}; my @input_features = @{ $input_features }; print join " ", @input_features; print "\n"; } }

In reply to Unicode combining characters as hash keys? 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.