#!/usr/bin/env perl
use feature ':5.10';
use strict;
use warnings;

use Unicode::UCD 'charinfo';
use Text::Unidecode;
use Data::Dump 'dump';

sub new_trans
{
    my $char_name = shift;

    if (my $info = charinfo($char_name)) {
        my $chr = chr hex $info->{code};
        my $t;
        if ($t = unidecode($chr) and $t ne '[?]') {
            return $t;
        }
    }

    return;
}

while (<>)
{
    chomp;

    if (/^U\+/) {
        my ($char_name, $trans, $annotate) = $_ =~ m[^(U\+\S+)\s+(\S+)\s+(.*)];
        my $new_trans;

        if ($trans eq '?' and ($new_trans = new_trans($char_name))) {
            say "$char_name  $new_trans" . (" " x (10 - length($new_trans))) . "$annotate";
        } else {
            say;
        }
    } else {
        say;
    }
}
