珀尔 |长度()函数
Perl 中的 length()函数查找给定字符串的长度(字符数),如果未指定,则为 $_。
Syntax:length(VAR)
Parameter:
VAR: String or a group of strings whose length is to be calculated
Return:
Returns the size of the string.
示例 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";
输出:
Length of String is: 15
示例 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";
输出:
Length of String is: 20
注意:如果要确定相应的大小,则使用数组或散列上的标量上下文。