# perldoc > Unicode::UCD

---
type: CommandReference
command: Unicode::UCD
mode: perldoc
section: ""
source: perldoc
---

## Quick Reference

- `use Unicode::UCD 'charinfo'; my $info = charinfo($codepoint);` — get hash of Unicode properties for a code point
- `use Unicode::UCD 'charprop'; my $val = charprop($codepoint, $property);` — get value of any Unicode property
- `use Unicode::UCD 'charblock'; my $block = charblock($codepoint);` — get block name; or `charblock('BlockName')` returns range set
- `use Unicode::UCD 'charscript'; my $script = charscript($codepoint);` — get script name; or `charscript('ScriptName')` returns range set
- `use Unicode::UCD 'casefold'; my $fold = casefold($codepoint);` — get case folding hash
- `use Unicode::UCD 'num'; my $val = num($string);` — get numeric value of a Unicode string
- `use Unicode::UCD 'prop_aliases'; my @names = prop_aliases($name);` — list synonyms for a property name
- `use Unicode::UCD 'prop_invlist'; my @ranges = prop_invlist($property);` — get inversion list for binary property
- `use Unicode::UCD 'prop_invmap'; my ($list, $map, $format, $default) = prop_invmap($property);` — full mapping for a property
- `my $version = Unicode::UCD::UnicodeVersion();` — get Unicode version string

## Name

Unicode::UCD - Unicode character database

## Synopsis

perl
use Unicode::UCD 'charinfo';
my $charinfo   = charinfo($codepoint);

use Unicode::UCD 'charprop';
my $value  = charprop($codepoint, $property);

use Unicode::UCD 'charprops_all';
my $all_values_hash_ref = charprops_all($codepoint);

use Unicode::UCD 'casefold';
my $casefold = casefold($codepoint);

use Unicode::UCD 'all_casefolds';
my $all_casefolds_ref = all_casefolds();

use Unicode::UCD 'casespec';
my $casespec = casespec($codepoint);

use Unicode::UCD 'charblock';
my $charblock  = charblock($codepoint);

use Unicode::UCD 'charscript';
my $charscript = charscript($codepoint);

use Unicode::UCD 'charblocks';
my $charblocks = charblocks();

use Unicode::UCD 'charscripts';
my $charscripts = charscripts();

use Unicode::UCD qw(charscript charinrange);
my $range = charscript($script);
print "looks like $script\n" if charinrange($range, $codepoint);

use Unicode::UCD qw(general_categories bidi_types);
my $categories = general_categories();
my $types = bidi_types();

use Unicode::UCD 'prop_aliases';
my @space_names = prop_aliases("space");

use Unicode::UCD 'prop_value_aliases';
my @gc_punct_names = prop_value_aliases("Gc", "Punct");

use Unicode::UCD 'prop_values';
my @all_EA_short_names = prop_values("East_Asian_Width");

use Unicode::UCD 'prop_invlist';
my @puncts = prop_invlist("gc=punctuation");

use Unicode::UCD 'prop_invmap';
my ($list_ref, $map_ref, $format, $missing) = prop_invmap("General Category");

use Unicode::UCD 'search_invlist';
my $index = search_invlist(\@invlist, $code_point);

use Unicode::UCD 'compexcl';
my $compexcl = compexcl($codepoint);

use Unicode::UCD 'namedseq';
my $namedseq = namedseq($named_sequence_name);

my $unicode_version = Unicode::UCD::UnicodeVersion();

my $convert_to_numeric = Unicode::UCD::num("\N{RUMI DIGIT ONE}\N{RUMI DIGIT TWO}");
## Functions

### `charinfo($codepoint)`

Returns a hash reference with fields: `code`, `name`, `category`, `combining`, `bidi`, `decomposition`, `decimal`, `digit`, `numeric`, `mirrored`, `unicode10`, `comment`, `upper`, `lower`, `title`, `block`, `script`. Returns `undef` for unassigned or non-characters.

### `charprop($codepoint, $property)`

Returns the value of any Unicode property for the code point. Property names follow loose matching. Returns a scalar (string or number). For properties like `Decomposition_Mapping`, the result may be intermediate. For `Name_Alias`, multiple synonyms are comma-separated. For `Script_Extensions`, multiple scripts are comma-separated. For `Numeric_Value`, fractions are converted to floating point.

### `charprops_all($codepoint)`

Returns a hash reference of all distinct Unicode properties and their values for the code point. Expensive.

### `charblock($codepoint)`

Returns the old-style block name for the code point (e.g., "Basic Latin"). If the argument is not a code point, interprets it as a block name and returns a range set (array of `[start, end, name]`). Returns `undef` for unknown blocks.

### `charscript($codepoint)`

Returns the script name (e.g., "Latin"). If the argument is not a code point, interprets it as a script name and returns a range set. Returns `undef` for unknown scripts. Prefer `charprop` with `Script_Extensions` for improved coverage.

### `charblocks()`

Returns a hash reference mapping old-style block names to their range sets.

### `charscripts()`

Returns a hash reference mapping script names to their range sets. Use `prop_invmap("scx")` instead for `Script_Extensions`. Use `prop_values("Script")` for a simple list of script names.

### `charinrange($range_set, $codepoint)`

Tests if a code point is in a range set returned by `charblock` or `charscript`. Returns true if within any range.

### `general_categories()`

Returns a hash reference mapping short general category names (e.g., "Lu") to long names (e.g., "UppercaseLetter"). Reversible.

### `bidi_types()`

Returns a hash reference mapping short bidi type names (e.g., "L") to long names (e.g., "Left-to-Right"). Reversible.

### `compexcl($codepoint)`

Deprecated. Returns `undef` if the Unicode version is too old, otherwise returns true if the code point is a composition exclusion (based on the `Composition_Exclusion` property, not `Full_Composition_Exclusion`). Use `chr($codepoint) =~ /\p{Full_Composition_Exclusion}/` instead.

### `casefold($codepoint)`

Returns a hash reference with fields: `code`, `full`, `simple`, `mapping`, `status`, `turkic`. Returns `undef` if no case folding exists. The `full` field contains the best fold (may be multiple code points). The `simple` field is a single code point alternative. The `turkic` field holds locale-specific folds. The `status` is "C", "S", "F", or "I" (for old Unicode versions). See Unicode TR21.

### `all_casefolds()`

Returns a hash reference where keys are decimal ordinals of characters with case folds, and values are the same hash as returned by `casefold()`. Example: `all_casefolds()->{ord("A")}` is equivalent to `casefold(ord("A"))`.

### `casespec($codepoint)`

Returns locale-dependent case mappings. Returns `undef` if all mappings are single code point and locale-independent. Otherwise returns a hash reference with keys: `code`, `lower`, `title`, `upper`, `condition`. If locale-specific rules exist, additional keys for locale names (e.g., "lt", "tr", "az") are present, each a hash reference with the same structure.

### `namedseq($name)`

In scalar context, returns the string of code points for a named sequence. In list context, returns the list of ordinals. With no arguments, returns a hash of all named sequences. Returns `undef` for unknown names.

### `num($string [, \$valid_length])`

Returns the numeric value of a Unicode string. For single characters, uses Unicode numeric value. For multi-character strings, returns `undef` unless all characters are decimal digits from the same script and same form. Sets `$valid_length` to the length of the valid initial substring. Returns `undef` for invalid strings.

### `prop_aliases($name)`

Returns a list of synonyms for a Unicode property name. In scalar context, returns the long name. The 0th element is the short name, 1st is the long name, rest are other synonyms. Accepts loose matching. Returns `undef` for unknown properties. Does not handle `Is_` prefix for standard properties, but does for Perl extensions.

### `prop_values($property)`

Returns a list of allowed values for a property with a restricted set (e.g., binary properties). Returns `undef` if the property has no restricted set. Uses loose matching. For block property, returns new-style block names.

### `prop_value_aliases($property, $value)`

Returns a list of synonyms for a property value. In scalar context, returns the long name. The 0th element is the short name, 1st is the long name, rest are other synonyms. For properties without synonyms, returns the input value normalized. For block property, returns new-style names.

### `prop_invlist($property)`

Returns an inversion list (array of code points) for a binary property or `property=value` pair. Each element toggles whether the range has the property. Returns `undef` for unknown properties. Use `search_invlist` to find a code point.

### `prop_invmap($property)`

Returns a four-element list: `($list_ref, $map_ref, $format, $default)`. `$list_ref` is an inversion list of range beginnings. `$map_ref` is the corresponding mapping values. `$format` indicates the type of mapping: `s` (simple scalars), `sl` (some lists), `a` (adjustable integers), `al` (some lists with adjustable), `ae` (adjustable with empty strings), `ale` (combination), `ar` (rational numbers), `n` (name property), `ad` (decomposition). `$default` is the value for most code points. Returns empty list for unknown properties.

### `search_invlist($invlist, $code_point)`

Searches an inversion list for a code point. Returns the index of the range containing the code point, or `undef` if not found. For `prop_invlist`, even index means the code point is in the property.

### `Unicode::UCD::UnicodeVersion()`

Returns the version of the Unicode Character Database as a string (e.g., "6.0.0").

## Examples

**Get charinfo for a character:**

perl
use Unicode::UCD 'charinfo';
my $info = charinfo(0x41);
print "Name: $info->{name}\n";  # LATIN CAPITAL LETTER A
**Get a property value with charprop:**

perl
use Unicode::UCD 'charprop';
print charprop(0x41, "General_Category"), "\n";  # Lu
**Case folding example:**

perl
use Unicode::UCD 'casefold';
my $fold = casefold(0xDF);
if (defined $fold) {
    my @full = split / /, $fold->{'full'};
    print "Full fold: ", map { chr(hex($_)) } @full, "\n";  # "ss"
}
**Using prop_invmap to get block names:**

perl
use Unicode::UCD 'prop_invmap';
my ($ranges, $maps, $format, $default) = prop_invmap("Block");
my $index = search_invlist($ranges, 0x41);
print "Block for U+0041: $maps->[$index]\n";  # Basic Latin
**Getting numeric value of a fraction:**

perl
use Unicode::UCD 'num';
my $val = num("\N{VULGAR FRACTION 1/4}");
print $val;  # 0.25
## See Also

- [Unicode::Normalize](https://www.chedong.com/phpMan.php/perldoc/Unicode%3A%3ANormalize/markdown) — for normalization and decomposition
- [charnames](https://www.chedong.com/phpMan.php/perldoc/charnames/markdown) — for `viacode` and `string_vianame`
- [Locale::Country](https://www.chedong.com/phpMan.php/perldoc/Locale%3A%3ACountry/markdown) — for locale codes
- [Locale::Language](https://www.chedong.com/phpMan.php/perldoc/Locale%3A%3ALanguage/markdown) — for language codes
- [perluniprops](https://www.chedong.com/phpMan.php/perldoc/perluniprops/markdown) — list of Unicode properties accessible through this module
- Unicode Standard Annex #24: Script Property (http://www.unicode.org/reports/tr24/)
- Unicode Standard Annex #44: Unicode Character Database (http://www.unicode.org/reports/tr44/)