unicode, \N, \x, character encoding
caseyperkins
created: 2006-03-02 14:38:24
Hi,
I'm trying to translate some special characters into unicoded Greek.

#This works:
use charnames ':full';
print("\N{GREEK SMALL LETTER EPSILON}\n");

#But this doesn't:
use charnames ':full';
$var = 'GREEK SMALL LETTER EPSILON';
print("\N{$var}\n");

It gives this error:
Unknown charname '$var' at C:/Perl/lib/charnames.pm line 32.
Propagated at un.pl line 3, within string Execution of un.pl aborted due to compilation errors.
shell returned 255

I need to pass the character name at runtime. But I see in the manpages that \N does not accept a variable. Nor does \x, it seems. The manpages suggest using charnames::vianame(), but all that does is return a character code, whereas I'm interested in getting back the actual unicoded character. Can anyone suggest a solution?

Many thanks.

Casey
Re: unicode, \N, \x, character encoding
created: 2006-03-02 14:47:13
\N escapes are seen pre-interpolation. I suggest chr(charnames::vianame($name)).

Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart
Re^2: unicode, \N, \x, character encoding
created: 2006-03-02 15:06:08
Hi Jeff,
It worked! Your help is greatly appreciated.
:-)

Casey
Re: unicode, \N, \x, character encoding
created: 2006-03-03 02:34:04

perlmonks.org content © perlmonks.org and ambrus, caseyperkins, japhy

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03