What is string.length() in Perl?

The length() function in Perl is used to calculate the size of a string.

The illustration below shows the visual representation of the length() function.

Figure 1: Visual representation of length() function

Syntax

length(string)

Parameters

The length() function requires a string as a parameter.

Return value

This function returns the size of a string.

If the string parameter is omitted, then it returns ''.

Code

#string
print "length('Hello') : ".length('Hello'). "\n";
#string with number
print "length('EDUCATIVE09') : ".length('EDUCATIVE09'). "\n";
#string is omitted
print "length() : ".length(). "\n";

Free Resources