#!/usr/bin/env perl use strict; use warnings; use autodie; use charnames ':full'; my $in_map = 'pm_unicode_1061453_map2.txt'; my $in_words = 'pm_unicode_1061453_greekwords1.txt'; my $out_greek = 'pm_unicode_1061453_greek_out.txt'; my $in_map_re = qr{^([^#]+)\s###[^#]+###\s([^#]+?)\s*$}; open my $in_map_fh, '<', $in_map; my %uni_map = map { /$in_map_re/ ? ($1 => $2) : () } <$in_map_fh>; close $in_map_fh; open my $in_words_fh, '<', $in_words; open my $out_greek_fh, '>:utf8', $out_greek; while (<$in_words_fh>) { chomp; my @word_chars = split ''; my $greek_word = ''; my $key = ''; while (@word_chars) { $key .= shift @word_chars; next unless exists $uni_map{$key}; next if @word_chars && exists $uni_map{join '' => $key, $word_chars[0]}; $greek_word .= charnames::string_vianame($uni_map{$key}); $key = ''; } die "Can't find charname for '$key'" if $key; print $out_greek_fh "$greek_word\n"; } close $in_words_fh; close $out_greek_fh;