What is the string.ucfirst() function in Perl?

The ucfirst() function in Perl converts the first character of a string to uppercase.

The following figure shows a visual representation of the ucfirst() function.

Figure 1: Visual representation of ucfirst() function

Syntax


ucfirst(string)

Parameter

As a parameter, the ucfirst() function requires a string whose first character is to be converted to uppercase.

Return value

The ucfirst() function converts the first character of a string to uppercase.


The rest of the string i.e. other than the first character, stays the same.


If the string parameter is omitted, then it returns $_.

Code

#string
print "ucfirst('educative') : ".ucfirst('educative'). "\n";
#string with number
print "ucfirst('educaTive09') : ".ucfirst('educaTive09'). "\n";
#string is omitted
print "ucfirst() : ".ucfirst(). "\n";

Free Resources