From: Jarkko Hietaniemi Date: Fri, 4 May 2001 03:51:39 +0000 (+0000) Subject: Encode/IO doc tweaks. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e9692b5b6f1d7184d1c98b2feeebc0e5e64ddad3;p=p5sagit%2Fp5-mst-13.2.git Encode/IO doc tweaks. p4raw-id: //depot/perl@9985 --- diff --git a/ext/Encode/Encode.pm b/ext/Encode/Encode.pm index 49e2d1e..104da00 100644 --- a/ext/Encode/Encode.pm +++ b/ext/Encode/Encode.pm @@ -530,7 +530,7 @@ L. Convert B the data between two encodings. How did the data in $string originally get to be in FROM_ENCODING? Either using -encode() or through PerlIO: See L. For CHECK +encode() or through PerlIO: See L. For CHECK see L. For example to convert ISO 8859-1 data to UTF-8: @@ -705,8 +705,8 @@ names for the iso-8859-* family. =head2 Defining Encodings - use Encode qw(define_alias); - define_encoding( $object, 'canonicalName' [,alias...]); + use Encode qw(define_alias); + define_encoding( $object, 'canonicalName' [,alias...]); Causes I to be associated with I<$object>. The object should provide the interface described in L @@ -721,14 +721,14 @@ If Perl is configured to use the new 'perlio' IO system then C provides a "layer" (See L) which can transform data as it is read or written. - open(my $ilyad,'>:encoding(iso-8859-7)','ilyad.greek'); - print $ilyad @epic; + open(my $ilyad,'>:encoding(iso-8859-7)','ilyad.greek'); + print $ilyad @epic; In addition the new IO system can also be configured to read/write UTF-8 encoded characters (as noted above this is efficient): - open(my $fh,'>:utf8','anything'); - print $fh "Any \x{0021} string \N{SMILEY FACE}\n"; + open(my $fh,'>:utf8','anything'); + print $fh "Any \x{0021} string \N{SMILEY FACE}\n"; Either of the above forms of "layer" specifications can be made the default for a lexical scope with the C pragma. See L. @@ -750,29 +750,22 @@ characters into bytes using the API above before doing writes, and to transform the bytes read from a handle into characters before doing "character operations" (e.g. C, C, ...). -=head1 Encode and PerlIO - -The PerlIO layer (new since Perl 5.7) can be used to automatically -convert the data being read in or written out to be converted from -some encoding into Perl's internal encoding or from Perl's internal -encoding into some other encoding. - -Examples: - - open(my $f, "<:encoding(cp1252)") - - open(my $g, ">:encoding(iso-8859-1)") - You can also use PerlIO to convert larger amounts of data you don't want to bring into memory. For example to convert between ISO 8859-1 (Latin 1) and UTF-8 (or UTF-EBCDIC in EBCDIC machines): - open(F, "<:encoding(iso-8859-1)", "data.txt") or die $!; - open(G, ">:utf8", "data.utf") or die $!; - while () { print G } + open(F, "<:encoding(iso-8859-1)", "data.txt") or die $!; + open(G, ">:utf8", "data.utf") or die $!; + while () { print G } + + # Could also do "print G " but that would pull + # the whole file into memory just to write it out again. + +More examples: - # Could also do "print G " but that would pull - # the whole file into memory just to write it out again. + open(my $f, "<:encoding(cp1252)") + open(my $g, ">:encoding(iso-8859-2)") + open(my $h, ">:encoding(latin9)") # iso-8859-15 See L for more information.