珀尔 | ord()函数
ord()函数是 Perl 中的一个内置函数,它返回字符串第一个字符的 ASCII 值。该函数接受一个字符作为参数,并返回该字符串第一个字符的字符串值。
Syntax: ord string
Parameter:
This function accepts a single parameter ‘string’ from which we can get an ASCII value.
Returns:
an integer value which represents the ASCII value of the first character in the string passed to this function as a parameter.
例子:
Input: Geeksforgeeks
Output: 71
Explanation: The ASCII value of G is 71
Input: WelcometoGFG
Output: 87
Explanation: The ASCII value of W is 87
下面的程序说明了在 Perl 中使用 ord()函数:
方案一:
#!/usr/bin/perl -w
# ASCII value of 'G' is printed
print(ord('GeeksforGeeks'));
输出:
71
方案二:
#!/usr/bin/perl -w
# ASCII value of 'W' is printed
print(ord('WelcometoGFG'));
输出:
87