charnames - define character names for \N{named} string literal escape.
\N{named}
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";
Pragma use charnames supports arguments :full, :short and script names. If :full is present, for expansion of \N{CHARNAME}} string CHARNAME is first looked in the list of standard Unicode names of chars. If :short is present, and CHARNAME has the form SCRIPT:CNAME, then CNAME is looked up as a letter in script SCRIPT. If pragma use charnames is used with script name arguments, then for \N{CHARNAME}} the name CHARNAME is looked up as a letter in the given scripts (in the specified order).
use charnames
:full
:short
\N{CHARNAME}}
CHARNAME
SCRIPT:CNAME
CNAME
SCRIPT
For lookup of CHARNAME inside a given script SCRIPTNAME charcodes.pm looks for the names
SCRIPTNAME
SCRIPTNAME CAPITAL LETTER CHARNAME SCRIPTNAME SMALL LETTER CHARNAME SCRIPTNAME LETTER CHARNAME
in the table of standard Unicode names. If CHARNAME is lowercase, then the CAPITAL variant is ignored, otherwise SMALL variant is ignored.
CAPITAL
SMALL
The mechanism of translation is \N{...} escapes is general and not hardwired into charnames.pm. A module can install custom translations (inside the scope which uses the module) by the following magic incantation:
\N{...}
use
sub import { shift; $^H |= 0x20000; $^H{charnames} = \&translator; }
Here translator() is a subroutine which takes CHARNAME as an argument, and returns text to insert into the string instead of the \N{CHARNAME} escape. Since the text to insert should be different in utf8 mode and out of it, the function should check the current state of utf8-flag as in
\N{CHARNAME}
utf8
sub translator { if ($^H & 0x8) { return utf_translator(@_); } else { return no_utf_translator(@_); } }
Since evaluation of the translation function happens in a middle of compilation (of a string literal), the translation function should not do any evals or requires. This restriction should be lifted in a future version of Perl.
eval
require
To install lib, copy and paste the appropriate command in to your terminal.
cpanm
cpanm lib
CPAN shell
perl -MCPAN -e shell install lib
For more information on module installation, please visit the detailed CPAN module installation guide.