Edit D:\app\Administrator\product\11.2.0\dbhome_1\perl\html\lib\encoding\warnings.html
<?xml version="1.0" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>encoding::warnings - Warn on implicit encoding conversions</title> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <link rev="made" href="mailto:" /> </head> <body style="background-color: white"> <table border="0" width="100%" cellspacing="0" cellpadding="3"> <tr><td class="block" style="background-color: #cccccc" valign="middle"> <big><strong><span class="block"> encoding::warnings - Warn on implicit encoding conversions</span></strong></big> </td></tr> </table> <!-- INDEX BEGIN --> <div name="index"> <p><a name="__index__"></a></p> <ul> <li><a href="#name">NAME</a></li> <li><a href="#version">VERSION</a></li> <li><a href="#synopsis">SYNOPSIS</a></li> <li><a href="#description">DESCRIPTION</a></li> <ul> <li><a href="#overview_of_the_problem">Overview of the problem</a></li> <li><a href="#detecting_the_problem">Detecting the problem</a></li> <li><a href="#solving_the_problem">Solving the problem</a></li> </ul> <li><a href="#caveats">CAVEATS</a></li> <li><a href="#see_also">SEE ALSO</a></li> <li><a href="#authors">AUTHORS</a></li> <li><a href="#copyright">COPYRIGHT</a></li> </ul> <hr name="index" /> </div> <!-- INDEX END --> <p> </p> <h1><a name="name">NAME</a></h1> <p>encoding::warnings - Warn on implicit encoding conversions</p> <p> </p> <hr /> <h1><a name="version">VERSION</a></h1> <p>This document describes version 0.11 of encoding::warnings, released June 5, 2007.</p> <p> </p> <hr /> <h1><a name="synopsis">SYNOPSIS</a></h1> <pre> use encoding::warnings; # or 'FATAL' to raise fatal exceptions</pre> <pre> utf8::encode($a = chr(20000)); # a byte-string (raw bytes) $b = chr(20000); # a unicode-string (wide characters)</pre> <pre> # "Bytes implicitly upgraded into wide characters as iso-8859-1" $c = $a . $b;</pre> <p> </p> <hr /> <h1><a name="description">DESCRIPTION</a></h1> <p> </p> <h2><a name="overview_of_the_problem">Overview of the problem</a></h2> <p>By default, there is a fundamental asymmetry in Perl's unicode model: implicit upgrading from byte-strings to unicode-strings assumes that they were encoded in <em>ISO 8859-1 (Latin-1)</em>, but unicode-strings are downgraded with UTF-8 encoding. This happens because the first 256 codepoints in Unicode happens to agree with Latin-1.</p> <p>However, this silent upgrading can easily cause problems, if you happen to mix unicode strings with non-Latin1 data -- i.e. byte-strings encoded in UTF-8 or other encodings. The error will not manifest until the combined string is written to output, at which time it would be impossible to see where did the silent upgrading occur.</p> <p> </p> <h2><a name="detecting_the_problem">Detecting the problem</a></h2> <p>This module simplifies the process of diagnosing such problems. Just put this line on top of your main program:</p> <pre> use encoding::warnings;</pre> <p>Afterwards, implicit upgrading of high-bit bytes will raise a warning. Ex.: <code>Bytes implicitly upgraded into wide characters as iso-8859-1 at - line 7</code>.</p> <p>However, strings composed purely of ASCII code points (<code>0x00</code>..<code>0x7F</code>) will <em>not</em> trigger this warning.</p> <p>You can also make the warnings fatal by importing this module as:</p> <pre> use encoding::warnings 'FATAL';</pre> <p> </p> <h2><a name="solving_the_problem">Solving the problem</a></h2> <p>Most of the time, this warning occurs when a byte-string is concatenated with a unicode-string. There are a number of ways to solve it:</p> <ul> <li><strong><a name="upgrade_both_sides_to_unicode_strings" class="item">Upgrade both sides to unicode-strings</a></strong> <p>If your program does not need compatibility for Perl 5.6 and earlier, the recommended approach is to apply appropriate IO disciplines, so all data in your program become unicode-strings. See <a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/lib/encoding.html">the encoding manpage</a>, <a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/lib/open.html">the open manpage</a> and <a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/pod/perlfunc.html#binmode">binmode in the perlfunc manpage</a> for how.</p> </li> <li><strong><a name="downgrade_both_sides_to_byte_strings" class="item">Downgrade both sides to byte-strings</a></strong> <p>The other way works too, especially if you are sure that all your data are under the same encoding, or if compatibility with older versions of Perl is desired.</p> <p>You may downgrade strings with <code>Encode::encode</code> and <code>utf8::encode</code>. See <a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/lib/Encode.html">the Encode manpage</a> and <a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/lib/utf8.html">the utf8 manpage</a> for details.</p> </li> <li><strong><a name="specify_the_encoding_for_implicit_byte_string_upgrading" class="item">Specify the encoding for implicit byte-string upgrading</a></strong> <p>If you are confident that all byte-strings will be in a specific encoding like UTF-8, <em>and</em> need not support older versions of Perl, use the <code>encoding</code> pragma:</p> <pre> use encoding 'utf8';</pre> <p>Similarly, this will silence warnings from this module, and preserve the default behaviour:</p> <pre> use encoding 'iso-8859-1';</pre> <p>However, note that <code>use encoding</code> actually had three distinct effects:</p> <ul> <li><strong><a name="perlio_layers_for_stdin_and_stdout" class="item">PerlIO layers for <strong>STDIN</strong> and <strong>STDOUT</strong></a></strong> <p>This is similar to what <a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/lib/open.html">the open manpage</a> pragma does.</p> </li> <li><strong><a name="literal_conversions" class="item">Literal conversions</a></strong> <p>This turns <em>all</em> literal string in your program into unicode-strings (equivalent to a <code>use utf8</code>), by decoding them using the specified encoding.</p> </li> <li><strong><a name="implicit_upgrading_for_byte_strings3" class="item">Implicit upgrading for byte-strings</a></strong> <p>This will silence warnings from this module, as shown above.</p> </li> </ul> <p>Because literal conversions also work on empty strings, it may surprise some people:</p> <pre> use encoding 'big5';</pre> <pre> my $byte_string = pack("C*", 0xA4, 0x40); print length $a; # 2 here. $a .= ""; # concatenating with a unicode string... print length $a; # 1 here!</pre> <p>In other words, do not <code>use encoding</code> unless you are certain that the program will not deal with any raw, 8-bit binary data at all.</p> <p>However, the <code>Filter => 1</code> flavor of <code>use encoding</code> will <em>not</em> affect implicit upgrading for byte-strings, and is thus incapable of silencing warnings from this module. See <a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/lib/encoding.html">the encoding manpage</a> for more details.</p> </ul> <p> </p> <hr /> <h1><a name="caveats">CAVEATS</a></h1> <p>For Perl 5.9.4 or later, this module's effect is lexical.</p> <p>For Perl versions prior to 5.9.4, this module affects the whole script, instead of inside its lexical block.</p> <p> </p> <hr /> <h1><a name="see_also">SEE ALSO</a></h1> <p><a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/pod/perlunicode.html">the perlunicode manpage</a>, <a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/pod/perluniintro.html">the perluniintro manpage</a></p> <p><a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/lib/open.html">the open manpage</a>, <a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/lib/utf8.html">the utf8 manpage</a>, <a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/lib/encoding.html">the encoding manpage</a>, <a href="file://C|\ADE\aime_smenon_perl_090715\perl\html/lib/Encode.html">the Encode manpage</a></p> <p> </p> <hr /> <h1><a name="authors">AUTHORS</a></h1> <p>Audrey Tang</p> <p> </p> <hr /> <h1><a name="copyright">COPYRIGHT</a></h1> <p>Copyright 2004, 2005, 2006, 2007 by Audrey Tang <<a href="mailto:cpan@audreyt.org">cpan@audreyt.org</a>>.</p> <p>This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.</p> <p>See <a href="http://www.perl.com/perl/misc/Artistic.html">http://www.perl.com/perl/misc/Artistic.html</a></p> <table border="0" width="100%" cellspacing="0" cellpadding="3"> <tr><td class="block" style="background-color: #cccccc" valign="middle"> <big><strong><span class="block"> encoding::warnings - Warn on implicit encoding conversions</span></strong></big> </td></tr> </table> </body> </html>
Ms-Dos/Windows
Unix
Write backup
jsp File Browser version 1.2 by
www.vonloesch.de