411 REFERENCE · Wikibooks
Perl Programming/Keywords/length
Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.
Perl le link Keywords
The length keyword
length is a function that returns how long the following expression is in terms of characters. If no EXPRESSION is given, it returns the length of $_. If the expression is undefined, undef is returned.
As length returns the number of logical characters, to find out the number of bytes in UTF-8, one has to enter an expression (see below).
Syntax
length EXPRESSION
Examples
use 5.10.0;
use Encode;
my $name = "Perl…";
say $name;
say length $name;
say length(encode_utf8($name)); Perl…
7
10 The result is the string $name, and the length of it both as logical characters & as UTF-8.
Perl le link Keywords