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"file "test_input.txt"d 0 0 a 0 1 ɑ̃ 1 0 s 1 1
the script itself:das dɑ̃s
#!/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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |