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