Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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"; } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Unicode combining characters as hash keys?
by ikegami (Patriarch) on Sep 02, 2011 at 21:36 UTC | |
by Anonymous Monk on Sep 03, 2011 at 08:11 UTC | |
by ikegami (Patriarch) on Sep 05, 2011 at 06:58 UTC | |
by Jim (Curate) on Sep 03, 2011 at 21:52 UTC | |
Re: Unicode combining characters as hash keys?
by Jim (Curate) on Sep 02, 2011 at 22:32 UTC | |
by Anonymous Monk on Sep 03, 2011 at 08:20 UTC |