avoid $@-clearing sideeffect of require in Carp
[p5sagit/p5-mst-13.2.git] / lib / utf8.pm
CommitLineData
a0ed51b3 1package utf8;
2
3sub import {
393fec97 4 $^H |= 0x00800000;
a0ed51b3 5 $enc{caller()} = $_[1] if $_[1];
6}
7
8sub unimport {
393fec97 9 $^H &= ~0x00800000;
a0ed51b3 10}
11
12sub AUTOLOAD {
13 require "utf8_heavy.pl";
14 goto &$AUTOLOAD;
15}
16
171;
18__END__
19
20=head1 NAME
21
393fec97 22utf8 - Perl pragma to enable/disable UTF-8 in source code
a0ed51b3 23
24=head1 SYNOPSIS
25
26 use utf8;
27 no utf8;
28
29=head1 DESCRIPTION
30
393fec97 31WARNING: The implementation of Unicode support in Perl is incomplete.
32Expect sudden and unannounced changes!
a0ed51b3 33
393fec97 34The C<use utf8> pragma tells the Perl parser to allow UTF-8 in the
35program text in the current lexical scope. The C<no utf8> pragma
36tells Perl to switch back to treating the source text as literal
37bytes in the current lexical scope.
a0ed51b3 38
393fec97 39This pragma is primarily a compatibility device. Perl versions
40earlier than 5.6 allowed arbitrary bytes in source code, whereas
41in future we would like to standardize on the UTF-8 encoding for
42source text. Until UTF-8 becomes the default format for source
43text, this pragma should be used to recognize UTF-8 in the source.
44When UTF-8 becomes the standard source format, this pragma will
45effectively become a no-op.
a0ed51b3 46
393fec97 47Enabling the C<utf8> pragma has the following effects:
a0ed51b3 48
393fec97 49=over
a0ed51b3 50
51=item *
52
393fec97 53Bytes in the source text that have their high-bit set will be treated
54as being part of a literal UTF-8 character. This includes most literals
55such as identifiers, string constants, constant regular expression patterns
56and package names.
a0ed51b3 57
58=item *
59
393fec97 60In the absence of inputs marked as UTF-8, regular expressions within the
61scope of this pragma will default to using character semantics instead
62of byte semantics.
a0ed51b3 63
393fec97 64 @bytes_or_chars = split //, $data; # may split to bytes if data
65 # $data isn't UTF-8
66 {
67 use utf8; # force char semantics
68 @chars = split //, $data; # splits characters
a0ed51b3 69 }
70
393fec97 71=head1 SEE ALSO
a0ed51b3 72
393fec97 73L<perlunicode>, L<byte>
a0ed51b3 74
75=cut