Bug#619214: perldoc -f length wrong about characters
jidanni at jidanni.org
jidanni at jidanni.org
Tue Mar 22 00:31:57 UTC 2011
Package: perl-doc
Version: 5.10.1-18
Severity: wishlist
It says
Note the characters: if the EXPR is in Unicode, you will get the number of characters, not
the number of bytes.
But I prove it wrong below.
$ perldoc -f length
length EXPR
length Returns the length in characters of the value of EXPR. If EXPR is omitted, returns length of
$_. Note that this cannot be used on an entire array or hash to find out how many elements
these have. For that, use "scalar @array" and "scalar keys %hash" respectively.
Note the characters: if the EXPR is in Unicode, you will get the number of characters, not
the number of bytes. To get the length of the internal string in bytes, use
"bytes::length(EXPR)", see bytes. Note that the internal encoding is variable, and the
number of bytes usually meaningless. To get the number of bytes that the string would have
when encoded as UTF-8, use "length(Encoding::encode_utf8(EXPR))".
$ perl -wle 'print length "網路;"'
9
$ perl -wle 'print length "網路"'
6
More information about the Perl-maintainers
mailing list