Book Home Programming PerlSearch this book

31.6. use charnames

use charnames HOW;
print "\N{CHARSPEC} is a funny character";

This lexically scoped pragma enables named characters to be interpolated into strings using the \N{CHARSPEC} notation:

use charnames ':full';
print "\N{GREEK SMALL LETTER SIGMA} is called sigma.\n";

use charnames ':short';
print "\N{greek:Sigma} is an upper-case sigma.\n";

use charnames qw(cyrillic greek);
print "\N{sigma} is Greek sigma, and \N{be} is Cyrillic b.\n";
The pragma supports HOW arguments :full and :short, as well as specific script names.[1] The HOW argument determines how the character specified by the CHARSPEC in \N{CHARSPEC}} is to be searched for. If :full is present, the CHARSPEC is first looked for in the Unicode character tables as a complete Unicode character name. If :short is present and CHARSPEC has the form SCRIPTNAME:CHARNAME, CHARNAME is looked for as a letter in script SCRIPTNAME. If HOW contains specific script names, CHARSPEC is looked for as an individual CHARNAME in each of the given scripts, in the specified order.

[1] By which we don't mean Perl scripts. We mean "script" as in some particular style of written letters, like Roman or Greek or Cyrillic. Unfortunately, "script" is the technical term for that, and we're not likely to persuade the Unicode Consortium to use a different term.

For lookup of CHARNAME inside a given script SCRIPTNAME, the pragma looks in the table of standard Unicode names for patterns of the form:

SCRIPTNAME CAPITAL LETTER CHARNAME
SCRIPTNAME SMALL LETTER CHARNAME
SCRIPTNAME LETTER CHARNAME
If CHARNAME is entirely lowercase (as in \N{sigma}), the CAPITAL variant is ignored. Otherwise, the SMALL variant is ignored.

You can write your own module that works like the charnames pragma but defines character names differently. However, the interface to that is still experimental, so see the manpage for the latest.



Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.