The Perl ucfirst function takes a string, converts its first character in uppercase and than returns the new string.The syntax forms of the ucfirst function are as follows:
It returns the value of EXPR with its first character in uppercase. If the argument is a string variable, this function returns the variable with its first character uppercase, but it doesn’t alter the content of the variable.
In the second syntax form, EXPR is omitted, so the Perl ucfirst function uses the special variable $_. As with other functions, you can use or omit the parentheses, as you like.
If the first letter of the string expression is uppercase, the function will do nothing.
The following simple example shows you how to convert the first character of a string in uppercase, using the Perl ucfirst function:
# initialize a string variable
my $str = "an example about ucfirst function";
my $newStr = ucfirst $str;
print "$newStr\n";
# it prints: An example about ucfirst function
Check my new How To Tutorial eBook (PDF format):to see a lot of fully commented examples that help you use the ucfirst function in your scripts.
NEW!!!
Do you want more information about the basic Perl topics?
Check my new "Perl How To" Tutorial eBooks page where I'll answer the most frequent questions regarding some topics :