Merge branch 'master' of http://repo.or.cz/r/msysgit into devel
[msysgit/historical-msysgit.git] / lib / perl5 / 5.6.1 / bytes.pm
blobf2f7e0157cb8a92ec97e4dab2e248dc23af56781
1 package bytes;
3 $bytes::hint_bits = 0x00000008;
5 sub import {
6 $^H |= $bytes::hint_bits;
9 sub unimport {
10 $^H &= ~$bytes::hint_bits;
13 sub AUTOLOAD {
14 require "bytes_heavy.pl";
15 goto &$AUTOLOAD;
18 sub length ($);
21 __END__
23 =head1 NAME
25 bytes - Perl pragma to force byte semantics rather than character semantics
27 =head1 SYNOPSIS
29 use bytes;
30 no bytes;
32 =head1 DESCRIPTION
34 WARNING: The implementation of Unicode support in Perl is incomplete.
35 See L<perlunicode> for the exact details.
37 The C<use bytes> pragma disables character semantics for the rest of the
38 lexical scope in which it appears. C<no bytes> can be used to reverse
39 the effect of C<use bytes> within the current lexical scope.
41 Perl normally assumes character semantics in the presence of character
42 data (i.e. data that has come from a source that has been marked as
43 being of a particular character encoding). When C<use bytes> is in
44 effect, the encoding is temporarily ignored, and each string is treated
45 as a series of bytes.
47 As an example, when Perl sees C<$x = chr(400)>, it encodes the character
48 in UTF8 and stores it in $x. Then it is marked as character data, so,
49 for instance, C<length $x> returns C<1>. However, in the scope of the
50 C<bytes> pragma, $x is treated as a series of bytes - the bytes that make
51 up the UTF8 encoding - and C<length $x> returns C<2>:
53 $x = chr(400);
54 print "Length is ", length $x, "\n"; # "Length is 1"
55 printf "Contents are %vd\n", $x; # "Contents are 400"
57 use bytes;
58 print "Length is ", length $x, "\n"; # "Length is 2"
59 printf "Contents are %vd\n", $x; # "Contents are 198.144"
62 For more on the implications and differences between character
63 semantics and byte semantics, see L<perlunicode>.
65 =head1 SEE ALSO
67 L<perlunicode>, L<utf8>
69 =cut