Thinko in #12783.
[p5sagit/p5-mst-13.2.git] / lib / encoding.pm
CommitLineData
0a378802 1package encoding;
2
3use Encode;
4
5sub import {
6 my ($class, $name) = @_;
7 $name = $ENV{PERL_ENCODING} if @_ < 2;
8 my $enc = find_encoding($name);
9 unless (defined $enc) {
10 require Carp;
11 Carp::croak "Unknown encoding '$name'";
12 }
13 ${^ENCODING} = $enc;
14}
15
16=pod
17
18=head1 NAME
19
20encoding - pragma to control the conversion of legacy data into Unicode
21
22=head1 SYNOPSIS
23
24 use encoding "iso 8859-7";
25
26 $a = "\xDF";
27 $b = "\x{100}";
28
29 $c = $a . $b;
30
31 # $c will be "\x{3af}\x{100}", not "\x{df}\x{100}".
32 # The \xDF of ISO 8859-7 is \x{3af} in Unicode.
33
34=head1 DESCRIPTION
35
36Normally when legacy 8-bit data is converted to Unicode the data is
37expected to be Latin-1 (or EBCDIC in EBCDIC platforms). With the
38encoding pragma you can change this default.
39
40The pragma is a per script, not a per block lexical. Only the last
9f4817db 41C<use encoding> matters, and it affects B<the whole script>.
0a378802 42
43=head1 FUTURE POSSIBILITIES
44
9f4817db 45The C<\x..> and C<\0...> in regular expressions are not
46affected by this pragma. They probably should.
47
48Also C<\N{...}> might become affected.
0a378802 49
50=head1 SEE ALSO
51
52L<perlunicode>
53
54=cut
55
561;