📜  珀尔 |长度()函数

📅  最后修改于: 2022-05-13 01:55:31.424000             🧑  作者: Mango

珀尔 |长度()函数

Perl 中的 length()函数查找给定字符串的长度(字符数),如果未指定,则为 $_。

示例 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

注意:如果要确定相应的大小,则使用数组或散列上的标量上下文。