Open In App

Perl | length() Function

Improve
Improve
Like Article
Like
Save
Share
Report

length() function in Perl finds length (number of characters) of a given string, or $_ if not specified.

Syntax:length(VAR)

Parameter:
VAR: String or a group of strings whose length is to be calculated
Return:
Returns the size of the string.

Example 1:




#!/usr/bin/perl
  
# String whose length is to be calculated
$orignal_string = "Geeks for Geeks";
  
# Function to calculate length
$string_len = length($orignal_string);
  
# Printing the Length
print "Length of String is: $string_len";


Output:

Length of String is: 15

 
Example 2:




#!/usr/bin/perl
  
# String whose length is to be calculated
$orignal_string = "123456 is Geeks Code";
  
# Function to calculate length
$string_len = length($orignal_string);
  
# Printing the Length
print "Length of String is: $string_len";


Output:

Length of String is: 20

Note : Scalar context on an array or hash is used if the corresponding size is to be determined.


Last Updated : 25 Jun, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads