- Perl ›
- Character code ›
- Unicode ›
- code point
How to find the code point of a character's Unicode
If you want to know the Unicode code point of a character, do the following: The utf8 pragma must be enabled and the source code must be saved in UTF-8.
use utf8; my $str = 'Ah'; # Displayed as hexadecimal printf "%x\n", ord($str);
You can know the code point of the character with the ord function. The printf function specifies the format %x and displays it in hexadecimal.
The output result is as follows, and you can see that the code point of the character "A" is 3042.
3042
Easily check with Data::Dumper
There is also a simple way to find out using the Data::Dumper module. This is because Data::Dumper converts any character that is not in the ASCII range to a code point when outputting the decoded string.
use utf8; my $str = 'Ah'; use Data::Dumper; print Dumper $str;
Unicode code points are output in hexadecimal as shown below.
$VAR1 = "\x{3042}";