By Alvin Alexander. Last updated: June 4, 2016
Perl string length FAQ: How do I get the length of a Perl string?
To get the length of a string in Perl, use the Perl length function, like this:
# perl string length example $size = length $last_name;
The variable $size
will now contain the string length, i.e., the number of characters in the variable named $last_name
.
Another Perl string length example
I just thought to write this article out here when I ran across the following Perl string length code:
$a = "foo, bar, and baz"; print length $a;
When you run this little snippet of Perl code, it prints the number 17, which is the length of the Perl string (i.e., the number of characters in the Perl string).