Compare the wincred helper against its original in compat.
[msysgit.git] / lib / perl5 / 5.8.8 / bytes.pm
bloba8222794ddf2ded9aa9ea00bb38d31482c3ccd30
1 package bytes;
3 our $VERSION = '1.02';
5 $bytes::hint_bits = 0x00000008;
7 sub import {
8 $^H |= $bytes::hint_bits;
11 sub unimport {
12 $^H &= ~$bytes::hint_bits;
15 sub AUTOLOAD {
16 require "bytes_heavy.pl";
17 goto &$AUTOLOAD if defined &$AUTOLOAD;
18 require Carp;
19 Carp::croak("Undefined subroutine $AUTOLOAD called");
22 sub length ($);
23 sub chr ($);
24 sub ord ($);
25 sub substr ($$;$$);
26 sub index ($$;$);
27 sub rindex ($$;$);
30 __END__
32 =head1 NAME
34 bytes - Perl pragma to force byte semantics rather than character semantics
36 =head1 SYNOPSIS
38 use bytes;
39 ... chr(...); # or bytes::chr
40 ... index(...); # or bytes::index
41 ... length(...); # or bytes::length
42 ... ord(...); # or bytes::ord
43 ... rindex(...); # or bytes::rindex
44 ... substr(...); # or bytes::substr
45 no bytes;
48 =head1 DESCRIPTION
50 The C<use bytes> pragma disables character semantics for the rest of the
51 lexical scope in which it appears. C<no bytes> can be used to reverse
52 the effect of C<use bytes> within the current lexical scope.
54 Perl normally assumes character semantics in the presence of character
55 data (i.e. data that has come from a source that has been marked as
56 being of a particular character encoding). When C<use bytes> is in
57 effect, the encoding is temporarily ignored, and each string is treated
58 as a series of bytes.
60 As an example, when Perl sees C<$x = chr(400)>, it encodes the character
61 in UTF-8 and stores it in $x. Then it is marked as character data, so,
62 for instance, C<length $x> returns C<1>. However, in the scope of the
63 C<bytes> pragma, $x is treated as a series of bytes - the bytes that make
64 up the UTF8 encoding - and C<length $x> returns C<2>:
66 $x = chr(400);
67 print "Length is ", length $x, "\n"; # "Length is 1"
68 printf "Contents are %vd\n", $x; # "Contents are 400"
70 use bytes; # or "require bytes; bytes::length()"
71 print "Length is ", length $x, "\n"; # "Length is 2"
72 printf "Contents are %vd\n", $x; # "Contents are 198.144"
75 chr(), ord(), substr(), index() and rindex() behave similarly.
77 For more on the implications and differences between character
78 semantics and byte semantics, see L<perluniintro> and L<perlunicode>.
80 =head1 LIMITATIONS
82 bytes::substr() does not work as an lvalue().
84 =head1 SEE ALSO
86 L<perluniintro>, L<perlunicode>, L<utf8>
88 =cut