1.5. Using Named Unicode Characters1.5.1. ProblemYou want to use Unicode names for fancy characters in your code without worrying about their code points. 1.5.2. SolutionPlace a use charnames at the top of your file, then freely insert "\N{CHARSPEC}" escapes into your string literals. 1.5.3. DiscussionThe use charnames pragma lets you use symbolic names for Unicode characters. These are compile-time constants that you access with the \N{CHARSPEC} double-quoted string sequence. Several subpragmas are supported. The :full subpragma grants access to the full range of character names, but you have to write them out in full, exactly as they occur in the Unicode character database, including the loud, all-capitals notation. The :short subpragma gives convenient shortcuts. Any import without a colon tag is taken to be a script name, giving case-sensitive shortcuts for those scripts.
Two functions, charnames::viacode and charnames::vianame, can translate between numeric code points and the long names. The Unicode documents use the notation U+XXXX to indicate the Unicode character whose code point is XXXX, so we'll use that here in our output.
Here's how to find the path to Perl's copy of the Unicode character database:
Read this file to learn the character names available to you. 1.5.4. See AlsoThe charnames(3) manpage and Chapter 31 of Programming Perl; the Unicode Character Database at http://www.unicode.org/
Copyright © 2003 O'Reilly & Associates. All rights reserved. |
|