5 $bytes::hint_bits = 0x00000008;
8 $^H |= $bytes::hint_bits;
12 $^H &= ~$bytes::hint_bits;
16 require "bytes_heavy.pl";
17 goto &$AUTOLOAD if defined &$AUTOLOAD;
19 Carp::croak("Undefined subroutine $AUTOLOAD called");
34 bytes - Perl pragma to force byte semantics rather than character semantics
38 This pragma reflects early attempts to incorporate Unicode into perl and
39 has since been superseded. It breaks encapsulation (i.e. it exposes the
40 innards of how the perl executable currently happens to store a string),
41 and use of this module for anything other than debugging purposes is
42 strongly discouraged. If you feel that the functions here within might be
43 useful for your application, this possibly indicates a mismatch between
44 your mental model of Perl Unicode and the current reality. In that case,
45 you may wish to read some of the perl Unicode documentation:
46 L<perluniintro>, L<perlunitut>, L<perlunifaq> and L<perlunicode>.
51 ... chr(...); # or bytes::chr
52 ... index(...); # or bytes::index
53 ... length(...); # or bytes::length
54 ... ord(...); # or bytes::ord
55 ... rindex(...); # or bytes::rindex
56 ... substr(...); # or bytes::substr
62 The C<use bytes> pragma disables character semantics for the rest of the
63 lexical scope in which it appears. C<no bytes> can be used to reverse
64 the effect of C<use bytes> within the current lexical scope.
66 Perl normally assumes character semantics in the presence of character
67 data (i.e. data that has come from a source that has been marked as
68 being of a particular character encoding). When C<use bytes> is in
69 effect, the encoding is temporarily ignored, and each string is treated
72 As an example, when Perl sees C<$x = chr(400)>, it encodes the character
73 in UTF-8 and stores it in $x. Then it is marked as character data, so,
74 for instance, C<length $x> returns C<1>. However, in the scope of the
75 C<bytes> pragma, $x is treated as a series of bytes - the bytes that make
76 up the UTF8 encoding - and C<length $x> returns C<2>:
79 print "Length is ", length $x, "\n"; # "Length is 1"
80 printf "Contents are %vd\n", $x; # "Contents are 400"
82 use bytes; # or "require bytes; bytes::length()"
83 print "Length is ", length $x, "\n"; # "Length is 2"
84 printf "Contents are %vd\n", $x; # "Contents are 198.144"
87 chr(), ord(), substr(), index() and rindex() behave similarly.
89 For more on the implications and differences between character
90 semantics and byte semantics, see L<perluniintro> and L<perlunicode>.
94 bytes::substr() does not work as an lvalue().
98 L<perluniintro>, L<perlunicode>, L<utf8>