perl function ord
The ord
function in Perl is used to convert the first character of a string to its ASCII value. This function takes one argument, which is the string whose first character's ASCII value needs to be determined.
Here's an example that demonstrates the usage of the ord
function:
my $first_letter = substr("Hello", 0, 1); my $ascii_value = ord($first_letter); print "The ASCII value of the first letter in 'Hello' is $ascii_value.\n";
In this example, we use the substr
function to extract the first character of the string "Hello"
. We then pass this character to the ord
function, which converts it to its ASCII value. Finally, we print out the ASCII value using the print
function.
The output of this program will be:
The ASCII value of the first letter in 'Hello' is 72.
This is because the ASCII value of the letter "H" is 72.