Perl | ord() Function
The ord() function is an inbuilt function in Perl that returns the ASCII value of the first character of a string. This function takes a character string as a parameter and returns the ASCII value of the first character of this string.
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.
Examples:
Input: Geeksforgeeks Output: 71 Explanation: The ASCII value of G is 71 Input: WelcometoGFG Output: 87 Explanation: The ASCII value of W is 87
Below programs illustrate the use of ord() function in Perl:
Program 1:
#!/usr/bin/perl -w # ASCII value of 'G' is printed print ( ord ( 'GeeksforGeeks' )); |
71
Program 2:
#!/usr/bin/perl -w # ASCII value of 'W' is printed print ( ord ( 'WelcometoGFG' )); |
87
Recommended Posts:
- Perl | cos() Function
- Perl | chr() Function
- Perl | uc() Function
- Perl | log() Function
- Perl | oct() Function
- Perl | exp Function
- Perl | each() Function
- Perl | hex Function
- Perl | abs() function
- Perl | tell() Function
- Perl | int() function
- Perl | sin() Function
- Perl | exists() Function
- Perl | split() Function
- Perl | getc Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.