> Hashes have no problem with combining marks.
Thanks for the confirmation, I thought that was how I understood the documentation, but I wasn't sure.> The problem is probably that the character appears both in composed and decomposed form.
If they do, I don't understand where it comes from. I entered them both in composed form. Note the two "a"-like things are different, but you only see it if you use a font that makes a difference between "small alpha" and "a".> You can use Unicode::Normalize's NFC or NFD to normalize the form.
Thanks. I read up on normalization and tried replacingwithmy $key = $1;
as well as replacing the last for-loop withmy $key = NFD($1); # or NFC, or even NFKD/NFKC
foreach my $letter (@letters) { my $norm_letter = NFD($letter); my @features = @{ $hash{$norm_letter} }; print join " ", @features; print "\n"; }
It still doesn't work though. The error message complains about not finding $nfd_letter in the hash, although the for-loop I commented out in the original script definitely shows it was added:
Can't use an undefined value as an ARRAY reference at ./test.plx line 31, <INPUTFILE> line 2.
The script is thus now (including the changes suggested by Jim, too):
use Unicode::Normalize; binmode(STDOUT, ':encoding(UTF-8)'); open HASH, '<:encoding(UTF-8)', 'test_hash.txt'; my %hash = (); while (my $line=<HASH>) { chomp $line; $line =~ s/^(.*?)\t//; my $key = NFD($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, '<:encoding(UTF-8)', 'test_input.txt'; while (my $entry = <INPUTFILE>) { chomp $entry; print $entry . "\n"; my @letters = $entry =~ /(\X)/g; foreach my $letter (@letters) { my $norm_letter = NFD($letter); my @features = @{ $hash{$norm_letter} }; print join " ", @features; print "\n"; } }
In reply to Re^2: Unicode combining characters as hash keys?
by Anonymous Monk
in thread Unicode combining characters as hash keys?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |