To convert the first character in a string to uppercase in Perl, you can use functions such as ucfirst()
.
In this example,
\$str1
with a value of "hello world"
.ucfirst()
function to capitalize the first character of \$str1
.\$str1 = "hello world";
\$modified_str1 = ucfirst(\$str1);
print "Modified string is: \$modified_str1\n";
Modified string is: Hello world
In this example,
\$str2
with a value of "perl"
.ucfirst()
function to capitalize the first character of \$str2
.\$str2 = "perl";
\$modified_str2 = ucfirst(\$str2);
print "Modified string is: \$modified_str2\n";
Modified string is: Perl
In this tutorial, we learned How to convert First Character in String to Uppercase in Perl language with well detailed examples.