- Perl ›
- builtin functions ›
- here
chr function - convert numbers to ASCII
You can use the chr function to convert a number to a character that corresponds to an ASCII (ASCII) code. If ASCII code is specified in the first argument, the corresponding character will be returned as the return value. This is the reverse of ord function.
my $char = chr $ascii_code;
Chr function example
This is an example to convert a numerical value to a character corresponding to ASCII code using the chr function.
use strict; use warnings; # In the ASCII character code, 65, 66, and 67 correspond to'A', ' B', and'C', respectively. my $a_num = 65; my $b_num = 66; my $c_num = 67; print chr($a_num) . "\n"; print chr($b_num) . "\n"; print chr($c_num) . "\n";