The Perl Conference Salt Lake City 2018 Banner

Perl Unicode Cookbook: Get Character Names by Number

℞ 6: Get character name by number

Unicode allows you to refer to characters by number or by name. Computers don’t care, but humans do. When you have a character number, you can translate it to its name with the charnames pragma:

use charnames ();
my $name = charnames::viacode(0x03A3);

charnames::viacode() returns the full Unicode name of the given codepoint—in this case, GREEK CAPITAL LETTER SIGMA. You may embed this as a literal string in your source code as "\N{GREEK CAPITAL LETTER SIGMA}".

Use charnames::string_vianame() to convert a Unicode name to the appropriate Unicode character during runtime.

Previous: ℞ 5: Unicode Literals by Number

Series Index: The Standard Preamble

Next: ℞ 7: Get Character Number by Name



Something wrong with this article? Help us out by opening an issue or pull request on GitHub