6 my ($class, $name) = @_;
7 $name = $ENV{PERL_ENCODING} if @_ < 2;
8 my $enc = find_encoding($name);
9 unless (defined $enc) {
11 Carp::croak "Unknown encoding '$name'";
20 encoding - pragma to control the conversion of legacy data into Unicode
24 use encoding "iso 8859-7";
26 # The \xDF of ISO 8859-7 is \x{3af} in Unicode.
31 printf "%#x\n", ord($a); # will print 0x3af, not 0xdf
35 # $c will be "\x{3af}\x{100}", not "\x{df}\x{100}".
39 Normally when legacy 8-bit data is converted to Unicode the data is
40 expected to be Latin-1 (or EBCDIC in EBCDIC platforms). With the
41 encoding pragma you can change this default.
43 The pragma is a per script, not a per block lexical. Only the last
44 C<use encoding> matters, and it affects B<the whole script>.
46 If no encoding is specified, the environment variable L<PERL_ENCODING>
47 is consulted. If no encoding can be found, C<Unknown encoding '...'>
50 =head1 FUTURE POSSIBILITIES
52 The C<\x..> and C<\0...> in regular expressions are not
53 affected by this pragma. They probably should.
55 Also chr(), ord(), and C<\N{...}> might become affected.
59 Cannot be combined with C<use utf8>. Note that this is a problem
60 B<only> if you would like to have Unicode identifiers in your scripts.
61 You should not need C<use utf8> for anything else these days
66 L<perlunicode>, L<encode>