- $x = chr(400);
- print "Length is ", length $x, "\n"; # "Length is 1"
- printf "Contents are %vd\n", $x; # "Contents are 400"
- {
- use bytes;
- print "Length is ", length $x, "\n"; # "Length is 2"
- printf "Contents are %vd\n", $x; # "Contents are 198.144"
- }
+ $x = chr(400);
+ print "Length is ", length $x, "\n"; # "Length is 1"
+ printf "Contents are %vd\n", $x; # "Contents are 400"
+ {
+ use bytes; # or "require bytes; bytes::length()"
+ print "Length is ", length $x, "\n"; # "Length is 2"
+ printf "Contents are %vd\n", $x; # "Contents are 198.144 (on
+ # ASCII platforms)"
+ }
+
+C<chr()>, C<ord()>, C<substr()>, C<index()> and C<rindex()> behave similarly.
+
+For more on the implications, see L<perluniintro> and L<perlunicode>.
+
+C<bytes::length()> is admittedly handy if you need to know the
+B<byte length> of a Perl scalar. But a more modern way is:
+
+ use Encode 'encode';
+ length(encode('UTF-8', $scalar))
+
+=head1 LIMITATIONS