™.. encoding::warnings - Online Linux Manual PageSection : 3pm
Updated : 2009-02-12
Source : perl v5.10.1
Note : Perl Programmers Reference Guide

NAMEencoding::warnings − Warn on implicit encoding conversions

VERSIONThis document describes version 0.11 of encoding::warnings, released June 5, 2007.

SYNOPSIS​ use encoding::warnings; # or 'FATAL' to raise fatal exceptions ​ ​ utf8::encode($a = chr(20000)); # a byte−string (raw bytes) ​ $b = chr(20000); # a unicode−string (wide characters) ​ ​ # "Bytes implicitly upgraded into wide characters as iso−8859−1" ​ $c = $a . $b;

DESCRIPTION

Overview of the problemBy 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 ISO 8859−1 (Latin−1), but unicode-strings are downgraded with UTF−8 encoding. This happens because the first 256 codepoints in Unicode happens to agree with Latin−1. 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.

Detecting the problemThis module simplifies the process of diagnosing such problems. Just put this line on top of your main program: ​ use encoding::warnings; Afterwards, implicit upgrading of high-bit bytes will raise a warning. Ex.: \*(C`Bytes implicitly upgraded into wide characters as iso\-8859\-1 at ​− line 7\*(C'\fR. However, strings composed purely of ASCII code points (0x00..0x7F) will not trigger this warning. You can also make the warnings fatal by importing this module as: ​ use encoding::warnings 'FATAL';

Solving the problemMost 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: • Upgrade both sides to unicode-strings 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 encoding, open and ​binmode in perlfunc for how. • Downgrade both sides to byte-strings 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. You may downgrade strings with \*(C`Encode::encode\*(C'\fR and \f(CW\*(C`utf8::encode\*(C'\fR. See Encode and utf8 for details. • Specify the encoding for implicit byte-string upgrading If you are confident that all byte-strings will be in a specific encoding like UTF−8, and need not support older versions of Perl, use the \*(C`encoding\*(C'\fR pragma: ​ use encoding 'utf8'; Similarly, this will silence warnings from this module, and preserve the default behaviour: ​ use encoding 'iso−8859−1'; However, note that \*(C`use encoding\*(C'\fR actually had three distinct effects: • PerlIO layers for STDIN and STDOUT This is similar to what open pragma does. • Literal conversions This turns all literal string in your program into unicode-strings (equivalent to a \*(C`use utf8\*(C'\fR), by decoding them using the specified encoding. • Implicit upgrading for byte-strings This will silence warnings from this module, as shown above. Because literal conversions also work on empty strings, it may surprise some people: ​ use encoding 'big5'; ​ ​ my $byte_string = pack("C*", 0xA4, 0x40); ​ print length $a; # 2 here. ​ $a .= ""; # concatenating with a unicode string... ​ print length $a; # 1 here! In other words, do not \*(C`use encoding\*(C'\fR unless you are certain that the program will not deal with any raw, 8−bit binary data at all. However, the \*(C`Filter => 1\*(C'\fR flavor of \f(CW\*(C`use encoding\*(C'\fR will \fInot\fR affect implicit upgrading for byte-strings, and is thus incapable of silencing warnings from this module. See encoding for more details.

CAVEATSFor Perl 5.9.4 or later, this module's effect is lexical. For Perl versions prior to 5.9.4, this module affects the whole script, instead of inside its lexical block.

SEE ALSOperlunicode, perluniintro open, utf8, encoding, Encode

AUTHORSAudrey Tang

COPYRIGHTCopyright 2004, 2005, 2006, 2007 by Audrey Tang <cpan@audreyt.org>. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See <http://www.perl.com/perl/misc/Artistic.html>
0
Johanes Gumabo
Data Size   :   15,131 byte
man-encoding::warnings.3pmBuild   :   2024-12-05, 20:55   :  
Visitor Screen   :   x
Visitor Counter ( page / site )   :   4 / 187,397
Visitor ID   :     :  
Visitor IP   :   18.119.19.251   :  
Visitor Provider   :   AMAZON-02   :  
Provider Position ( lat x lon )   :   39.962500 x -83.006100   :   x
Provider Accuracy Radius ( km )   :   1000   :  
Provider City   :   Columbus   :  
Provider Province   :   Ohio ,   :   ,
Provider Country   :   United States   :  
Provider Continent   :   North America   :  
Visitor Recorder   :   Version   :  
Visitor Recorder   :   Library   :  
Online Linux Manual Page   :   Version   :   Online Linux Manual Page - Fedora.40 - march=x86-64 - mtune=generic - 24.12.05
Online Linux Manual Page   :   Library   :   lib_c - 24.10.03 - march=x86-64 - mtune=generic - Fedora.40
Online Linux Manual Page   :   Library   :   lib_m - 24.10.03 - march=x86-64 - mtune=generic - Fedora.40
Data Base   :   Version   :   Online Linux Manual Page Database - 24.04.13 - march=x86-64 - mtune=generic - fedora-38
Data Base   :   Library   :   lib_c - 23.02.07 - march=x86-64 - mtune=generic - fedora.36

Very long time ago, I have the best tutor, Wenzel Svojanovsky . If someone knows the email address of Wenzel Svojanovsky , please send an email to johanes_gumabo@yahoo.co.id .
If error, please print screen and send to johanes_gumabo@yahoo.co.id
Under development. Support me via PayPal.

ERROR : Need New Coding :         (parse_manual_page_|249|encoding::warnings.3pm|36/37|el══─{─══.|.el══─{─══. ds -- \|\(em\| )         (htmlprn|149|encoding::warnings.3pm|36/37|.el══─{─══. ds --  —  |.el══─{─══. ds -- \|\(em\| )         (parse_manual_page_|249|encoding::warnings.3pm|41|br══─}─══|'br══─}─══ )         (htmlprn|149|encoding::warnings.3pm|41|'br══─}─══ |'br══─}─══ )         (rof_nr_x|149|encoding::warnings.3pm|51/52|\nF|.ie \nF ══─{─══. de IX )         (rof_unit_scale_px|41|encoding::warnings.3pm|51/52|F|.ie \nF ══─{─══. de IX )         (rof_if|19|encoding::warnings.3pm|51/52|\nF|.ie \nF ══─{─══. de IX )         (htmlprn|149|encoding::warnings.3pm|51/52|.ie \nF ══─{─══. de IX|.ie \nF ══─{─══. de IX )         (rof_escape_sequence|91|encoding::warnings.3pm|53|\$1\t\\n%\t"\\$2" |. tm Index:\\$1\t\\n%\t"\\$2" )         (parse_manual_page_|249|encoding::warnings.3pm|57|══─}─══|.══─}─══ )         (htmlprn|149|encoding::warnings.3pm|57|.══─}─══ |.══─}─══ )         (rof_escape_sequence|91|encoding::warnings.3pm|160|\*(-- i.e. byte-strings encoded |to mix unicode strings with non\-Latin1 data \*(-- i.e. byte-strings encoded )         (rof_escape_sequence|91|encoding::warnings.3pm|174|\*(C`Bytes implicitly upgraded into wide characters as iso\-8859\-1 at |Ex.: \f(CW\*(C`Bytes implicitly upgraded into wide characters as iso\-8859\-1 at )         (rof_escape_sequence|91|encoding::warnings.3pm|175|\*(C'\fR. |\&\- line 7\*(C'\fR. )         (rof_escape_sequence|91|encoding::warnings.3pm|203|\*(C`Encode::encode\*(C'\fR and \f(CW\*(C`utf8::encode\*(C'\fR. |You may downgrade strings with \f(CW\*(C`Encode::encode\*(C'\fR and \f(CW\*(C`utf8::encode\*(C'\fR. )         (rof_escape_sequence|91|encoding::warnings.3pm|210|\*(C`encoding\*(C'\fR pragma: |use the \f(CW\*(C`encoding\*(C'\fR pragma: )         (rof_escape_sequence|91|encoding::warnings.3pm|223|\*(C`use encoding\*(C'\fR actually had three distinct effects: |However, note that \f(CW\*(C`use encoding\*(C'\fR actually had three distinct effects: )         (rof_escape_sequence|91|encoding::warnings.3pm|233|\*(C`use utf8\*(C'\fR), by decoding them using the specified |(equivalent to a \f(CW\*(C`use utf8\*(C'\fR), by decoding them using the specified )         (rof_escape_sequence|91|encoding::warnings.3pm|254|\*(C`use encoding\*(C'\fR unless you are certain that the |In other words, do not \f(CW\*(C`use encoding\*(C'\fR unless you are certain that the )         (rof_escape_sequence|91|encoding::warnings.3pm|257|\*(C`Filter => 1\*(C'\fR flavor of \f(CW\*(C`use encoding\*(C'\fR will \fInot\fR |However, the \f(CW\*(C`Filter => 1\*(C'\fR flavor of \f(CW\*(C`use encoding\*(C'\fR will \fInot\fR )