jdinesh has asked for the wisdom of the Perl Monks concerning the following question:

The symbol font alpha character value is 0xF061, I need to convert α using perl.
Perl5.6 working following regular expressions, but Perl5.8 does not work.
$lines=~s/\x{F061}/\&alpha\;/g;

can anyone help me, How to convert Unicode character to entity, and Symbol and other font character to entity.
JD

Replies are listed 'Best First'.
Re: Unicode to entity
by Louis_Wu (Chaplain) on Jan 10, 2003 at 06:43 UTC

    These modules should help you. If these don't scratch your itch, try searching CPAN for 'Unicode'.

    Unicode::CharName
    Converts between the character code and the Unicode character name, and gives you the class the character belongs to.
    Unicode::String
    Try the $us->utf8( [$newval] ) function. To quote the description from the page:
    The UTF-8 encoding use 8-bit for the encoding of characters in the range 0x0 .. 0x7F, 16-bit for the encoding of characters in the range 0x80 .. 0x7FF, 24-bit for the encoding of characters in the range 0x800 .. 0xFFFF and 32-bit for characters in the range 0x01000 .. 0x10FFFF. Americans like this encoding, because plain US-ASCII characters are still US-ASCII. Another benefit is that the character '\0' only occurs as the encoding of 0x0, thus the normal NUL-terminated strings (popular in the C programming language) can still be used.
    Unicode::Map8
    Quote the CPAN:
    The Unicode::Map8 class implement efficient mapping tables between 8-bit character sets and 16 bit character sets like Unicode. The tables are efficient both in terms of space allocated and translation speed. The 16-bit strings is assumed to use network byte order.

    BTW, I've never used these. I just searched CPAN.

Re: Unicode to entity
by Jaap (Curate) on Jan 10, 2003 at 11:33 UTC
    Perhaps you need to enable utf8 with "use utf8;" in your perl program.