Perl | length() Function

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

#!/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";

chevron_right


Output:

Length of String is: 15

 
Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

#!/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";

chevron_right


Output:

Length of String is: 20

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



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.