length doesn't know anything about encodings. It counts the characters in the string, whether those characters happen to be bytes, Unicode code points or something entirely different.
If you pass encoded text to it (bytes), it will count the bytes.
If you pass decoded text to it (Unicode code points), it will count the Unicode code points.
Bytes "\xC9\x72\x69\x63" String: C9 72 69 63 Length: 4 Unicode code points "\N{LATIN CAPITAL LETTER E WITH ACUTE}ric" String: C9 72 69 63 Length: 4 Unicode code points "\N{LATIN CAPITAL LETTER E WITH ACUTE}ric\N{RIGHT SINGLE QUOTATION MAR +K}s" String: C9 72 69 63 2019 73 Length: 6
There are many ways of creating each of the above strings. I just listed one as an example. It doesn't matter how the string is created.
In reply to Re: How does the built-in function length work?
by ikegami
in thread How does the built-in function length work?
by PerlOnTheWay
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |