Perl chr()函数
Perl中的chr()函数返回一个字符串,代表一个字符,其Unicode码位是一个整数。
语法: chr(Num)
参数:
Num: 是一个Unicode整数值,其对应的字符将被返回。
返回: 一个代表Unicode码位为整数的字符的字符串。
例1:
#!/usr/bin/perl
# Taking some unicode integer value as the parameter
# of the chr() function and returning the corresponding
# characters as output
print chr(71), chr(101), chr(101), chr(107), chr(115);
print "\n";
print chr(102), chr(111), chr(114);
print "\n";
print chr(71), chr(101), chr(101), chr(107), chr(115);
输出:
Geeks
for
Geeks
例2:
#!/usr/bin/perl
# Initialising an array of some unicode integer values
# and retrieving each value and printing their
# corresponding characters
my @Array = (71, 101, 101, 107, 115);
foreach my element (@Array) {
print chr(element);
}
输出 :
Geeks