perl function lcfirst
The lcfirst
function in Perl is used to convert the first character of a string to lowercase. It takes a single argument, which is the string to be converted, and returns the modified string.
Here's an example that demonstrates how to use lcfirst
:
#!/usr/bin/perl use strict; use warnings; # Define a string my $string = "Hello World"; # Convert the first character of the string to lowercase my $modified_string = lcfirst($string); # Print the original and modified strings print "Original string: $string\n"; print "Modified string: $modified_string\n";
In this example, we start by defining a string called "Hello World". We then use the lcfirst
function to convert the first character of the string to lowercase and store the modified string in a new variable called $modified_string
. Finally, we print both the original and modified versions of the string to the console.
When we run this script, we see that the original string is printed with the first letter capitalized, while the modified string is printed with the first letter in lowercase:
Original string: Hello World Modified string: hello World