File: Encode.html

package info (click to toggle)
perl-doc-html 5.26.0-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 39,400 kB
  • sloc: xml: 36; makefile: 7
file content (918 lines) | stat: -rw-r--r-- 74,571 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <title>Encode - perldoc.perl.org</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta http-equiv="Content-Language" content="en-gb">
  <link rel="search" type="application/opensearchdescription+xml" title="Search perldoc.perl.org" href="/static/search.xml"/>
  <link href="static/css-20100830.css" rel="stylesheet" rev="stylesheet" type="text/css" media="screen">
  <link href="static/exploreperl.css" rel="stylesheet" rev="stylesheet" type="text/css">
</head>

<body onLoad="perldoc.startup();" onPageShow="if (event.persisted) perldoc.startup();">
    <div id="page">
      
      <div id="header">
	<div id="homepage_link">
	  <a href="index.html"></a>
	</div>
	<div id="strapline">
	  Perl Programming Documentation
	</div>
	<div id="download_link" class="download">
	  <a href="http://www.perl.org/get.html">Download Perl</a>
	</div>
	<div id="explore_link" class="download">
	  <a id="explore_anchor" href="#">Explore</a>
	</div>
      </div>
      
      <div id="body">
        <div id="left_column">
          <div class="side_group">
            
	    <div class="side_panel doc_panel">
              <p>Manual</p>
              <ul>
                <li><a href="index-overview.html">Overview</a>
                <li><a href="index-tutorials.html">Tutorials</a>
                <li><a href="index-faq.html">FAQs</a>
                <li><a href="index-history.html">History / Changes</a>
                <li><a href="index-licence.html">License</a>
              </ul>
            </div>
            <div class="side_panel doc_panel">
              <p>Reference</p>
              <ul>
                <li><a href="index-language.html">Language</a>
                <li><a href="index-functions.html">Functions</a>
                <li><a href="perlop.html">Operators</a>
                <li><a href="perlvar.html">Special Variables</a>
                <li><a href="index-pragmas.html">Pragmas</a>
                <li><a href="index-utilities.html">Utilities</a>
                <li><a href="index-internals.html">Internals</a>
                <li><a href="index-platforms.html">Platform Specific</a>
              </ul>
            </div>
            <div class="side_panel doc_panel">
              <p>Modules</p>
              <ul>
		<li>
		
                
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		
                  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		
                  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		
                  
		
                  
		    
		  
		
                  
		
                  
		
		
                    <a href="index-modules-A.html">A</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-B.html">B</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-C.html">C</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-D.html">D</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-E.html">E</a>
                    
                      
                        <li>
                      
                    
                
                    <a href="index-modules-F.html">F</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-G.html">G</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-H.html">H</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-I.html">I</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-L.html">L</a>
                    
                      
                        <li>
                      
                    
                
                    <a href="index-modules-M.html">M</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-N.html">N</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-O.html">O</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-P.html">P</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-S.html">S</a>
                    
                      
                        <li>
                      
                    
                
                    <a href="index-modules-T.html">T</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-U.html">U</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-X.html">X</a>
                    
                
              </ul>
            </div>
            
	      <div class="side_panel doc_panel">
		<p>Tools</p>
		<ul>
		  <li><a href="preferences.html">Preferences</a>
		</ul>
	      </div>
            
          </div>
        </div>
        <div id="centre_column">
          <div id="content_header">
            <div id="title_bar">
              <div id="page_name">
                <h1>Encode</h1>
              </div>
              <div id="perl_version">
                Perl 5 version 26.0 documentation
              </div>
              <div class="page_links" id="page_links_top">
                <a href="#" onClick="toolbar.goToTop();return false;">Go to top</a>
		
              </div>
	      <div class="page_links" id="page_links_bottom">
		
                  <a href="#" id="page_index_toggle">Show page index</a> &bull;
		
                <a href="#" id="recent_pages_toggle">Show recent pages</a>		
	      </div>
	      <div id="search_form">
		<form action="search.html" method="GET" id="search">
		  <input type="text" name="q" id="search_box" alt="Search">
		</form>
	      </div>
            </div>
            <div id="breadcrumbs">
                
    <a href="index.html">Home</a> &gt;
    
      
        <a href="index-modules-E.html">Core modules (E)</a> &gt;
      
    
    Encode
  

            </div>
          </div>
          <div id="content_body">
	    <!--[if lt IE 7]>
 <div class="noscript">
   <p>
     <strong>It looks like you're using Internet Explorer 6. This is a very old
     browser which does not offer full support for modern websites.</strong>
   </p>
   <p>
     Unfortunately this means that this website will not work on
     your computer.
   </p>
   <p>
     Don't miss out though! To view the site (and get a better experience from
     many other websites), simply upgrade to
     <a href="http://www.microsoft.com/windows/Internet-explorer/default.aspx">Internet
Explorer 8</a>
     or download an alternative browser such as
     <a href="http://www.mozilla.com/en-US/firefox/firefox.html">Firefox</a>,
     <a href="http://www.apple.com/safari/download/">Safari</a>, or
     <a href="http://www.google.co.uk/chrome">Google Chrome</a>.
   </p>
   <p>
     All of these browsers are free. If you're using a PC at work, you may
     need to contact your IT administrator.
   </p>
 </div>
<![endif]-->
	    <noscript>
	      <div class="noscript">
	      <p>
                <strong>Please note: Many features of this site require JavaScript. You appear to have JavaScript disabled,
	        or are running a non-JavaScript capable web browser.</strong>
	      </p>
	      <p>
		To get the best experience, please enable JavaScript or download a modern web browser such as <a href="http://www.microsoft.com/windows/Internet-explorer/default.aspx">Internet Explorer 8</a>, <a href="http://www.mozilla.com/en-US/firefox/firefox.html">Firefox</a>, <a href="http://www.apple.com/safari/download/">Safari</a>, or <a href="http://www.google.co.uk/chrome">Google Chrome</a>.
              </p>
	      </div>
	    </noscript>

	    <div id="recent_pages" class="hud_container">
	      <div id="recent_pages_header" class="hud_header">
		<div id="recent_pages_close" class="hud_close"><a href="#" onClick="recentPages.hide();return false;"></a></div>
		<div id="recent_pages_title" class="hud_title"><span class="hud_span_top">Recently read</span></div>
		<div id="recent_pages_topright" class="hud_topright"></div>
	      </div>
	      <div id="recent_pages_content" class="hud_content">
	      </div>
	      <div id="recent_pages_footer" class="hud_footer">
		<div id="recent_pages_bottomleft" class="hud_bottomleft"></div>
		<div id="recent_pages_bottom" class="hud_bottom"><span class="hud_span_bottom"></span></div>
		<div id="recent_pages_resize" class="hud_resize"></div>
	      </div>
	    </div>
  
	    <div id="from_search"></div>
            <h1>Encode</h1>


  <!--    -->
<ul><li><a href="#NAME">NAME</a><li><a href="#SYNOPSIS">SYNOPSIS</a><ul><li><a href="#Table-of-Contents">Table of Contents</a></ul><li><a href="#DESCRIPTION">DESCRIPTION</a><ul><li><a href="#TERMINOLOGY">TERMINOLOGY</a></ul><li><a href="#THE-PERL-ENCODING-API">THE PERL ENCODING API</a><ul><li><a href="#Basic-methods">Basic methods</a><li><a href="#Listing-available-encodings">Listing available encodings</a><li><a href="#Defining-Aliases">Defining Aliases</a><li><a href="#Finding-IANA-Character-Set-Registry-names">Finding IANA Character Set Registry names</a></ul><li><a href="#Encoding-via-PerlIO">Encoding via PerlIO</a><li><a href="#Handling-Malformed-Data">Handling Malformed Data</a><ul><li><a href="#List-of-_CHECK_-values">List of _CHECK_ values</a><li><a href="#coderef-for-CHECK">coderef for CHECK</a></ul><li><a href="#Defining-Encodings">Defining Encodings</a><li><a href="#The-UTF8-flag">The UTF8 flag</a><ul><li><a href="#Messing-with-Perl's-Internals">Messing with Perl's Internals</a></ul><li><a href="#UTF-8-vs.-utf8-vs.-UTF8">UTF-8 vs. utf8 vs. UTF8</a><li><a href="#SEE-ALSO">SEE ALSO</a><li><a href="#MAINTAINER">MAINTAINER</a><li><a href="#COPYRIGHT">COPYRIGHT</a></ul><a name="NAME"></a><h1>NAME</h1>
<p>Encode - character encodings in Perl</p>
<a name="SYNOPSIS"></a><h1>SYNOPSIS</h1>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/use.html">use</a> <span class="w">Encode</span> <span class="q">qw(decode encode)</span><span class="sc">;</span></li><li>    <span class="i">$characters</span> = <span class="i">decode</span><span class="s">(</span><span class="q">&#39;UTF-8&#39;</span><span class="cm">,</span> <span class="i">$octets</span><span class="cm">,</span>     <span class="w">Encode::FB_CROAK</span><span class="s">)</span><span class="sc">;</span></li><li>    <span class="i">$octets</span>     = <span class="i">encode</span><span class="s">(</span><span class="q">&#39;UTF-8&#39;</span><span class="cm">,</span> <span class="i">$characters</span><span class="cm">,</span> <span class="w">Encode::FB_CROAK</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><a name="Table-of-Contents"></a><h2>Table of Contents</h2>
<p>Encode consists of a collection of modules whose details are too extensive
to fit in one document.  This one itself explains the top-level APIs
and general topics at a glance.  For other topics and more details,
see the documentation for these modules:</p>
<ul>
<li><a name="the-Encode%3a%3aAlias-manpage---Alias-definitions-to-encodings"></a><b><a href="Encode/Alias.html">Encode::Alias</a> - Alias definitions to encodings</b>
</li>
<li><a name="the-Encode%3a%3aEncoding-manpage---Encode-Implementation-Base-Class"></a><b><a href="Encode/Encoding.html">Encode::Encoding</a> - Encode Implementation Base Class</b>
</li>
<li><a name="the-Encode%3a%3aSupported-manpage---List-of-Supported-Encodings"></a><b><a href="Encode/Supported.html">Encode::Supported</a> - List of Supported Encodings</b>
</li>
<li><a name="the-Encode%3a%3aCN-manpage---Simplified-Chinese-Encodings"></a><b><a href="Encode/CN.html">Encode::CN</a> - Simplified Chinese Encodings</b>
</li>
<li><a name="the-Encode%3a%3aJP-manpage---Japanese-Encodings"></a><b><a href="Encode/JP.html">Encode::JP</a> - Japanese Encodings</b>
</li>
<li><a name="the-Encode%3a%3aKR-manpage---Korean-Encodings"></a><b><a href="Encode/KR.html">Encode::KR</a> - Korean Encodings</b>
</li>
<li><a name="the-Encode%3a%3aTW-manpage---Traditional-Chinese-Encodings"></a><b><a href="Encode/TW.html">Encode::TW</a> - Traditional Chinese Encodings</b>
</li>
</ul>
<a name="DESCRIPTION"></a><h1>DESCRIPTION</h1>
<p>The <code class="inline"><span class="w">Encode</span></code>
 module provides the interface between Perl strings
and the rest of the system.  Perl strings are sequences of
<i>characters</i>.</p>
<p>The repertoire of characters that Perl can represent is a superset of those
defined by the Unicode Consortium. On most platforms the ordinal
values of a character as returned by <code class="inline">ord(<i>S</i>)</code> is the <i>Unicode
codepoint</i> for that character. The exceptions are platforms where
the legacy encoding is some variant of EBCDIC rather than a superset
of ASCII; see <a href="perlebcdic.html">perlebcdic</a>.</p>
<p>During recent history, data is moved around a computer in 8-bit chunks,
often called "bytes" but also known as "octets" in standards documents.
Perl is widely used to manipulate data of many types: not only strings of
characters representing human or computer languages, but also "binary"
data, being the machine's representation of numbers, pixels in an image, or
just about anything.</p>
<p>When Perl is processing "binary data", the programmer wants Perl to
process "sequences of bytes". This is not a problem for Perl: because a
byte has 256 possible values, it easily fits in Perl's much larger
"logical character".</p>
<p>This document mostly explains the <i>how</i>. <a href="perlunitut.html">perlunitut</a> and <a href="perlunifaq.html">perlunifaq</a>
explain the <i>why</i>.</p>
<a name="TERMINOLOGY"></a><h2>TERMINOLOGY</h2>
<a name="character"></a><h3>character</h3>
<p>A character in the range 0 .. 2**32-1 (or more);
what Perl's strings are made of.</p>
<a name="byte"></a><h3>byte</h3>
<p>A character in the range 0..255;
a special case of a Perl character.</p>
<a name="octet"></a><h3>octet</h3>
<p>8 bits of data, with ordinal values 0..255;
term for bytes passed to or from a non-Perl context, such as a disk file,
standard I/O stream, database, command-line argument, environment variable,
socket etc.</p>
<a name="THE-PERL-ENCODING-API"></a><h1>THE PERL ENCODING API</h1>
<a name="Basic-methods"></a><h2>Basic methods</h2>
<a name="encode"></a><h3>encode</h3>
<pre class="verbatim"><ol><li>  <span class="i">$octets</span>  = <span class="i">encode</span><span class="s">(</span><span class="w">ENCODING</span><span class="cm">,</span> <span class="w">STRING</span><span class="s">[</span><span class="cm">,</span> <a class="l_k" href="functions/CHECK.html">CHECK</a><span class="s">]</span><span class="s">)</span></li></ol></pre><p>Encodes the scalar value <i>STRING</i> from Perl's internal form into
<i>ENCODING</i> and returns a sequence of octets.  <i>ENCODING</i> can be either a
canonical name or an alias.  For encoding names and aliases, see
<a href="#Defining-Aliases">Defining Aliases</a>.  For CHECK, see <a href="#Handling-Malformed-Data">Handling Malformed Data</a>.</p>
<p><b>CAVEAT</b>: the input scalar <i>STRING</i> might be modified in-place depending
on what is set in CHECK. See <a href="#LEAVE_SRC">LEAVE_SRC</a> if you want your inputs to be
left unchanged.</p>
<p>For example, to convert a string from Perl's internal format into
ISO-8859-1, also known as Latin1:</p>
<pre class="verbatim"><ol><li>  <span class="i">$octets</span> = <span class="i">encode</span><span class="s">(</span><span class="q">&quot;iso-8859-1&quot;</span><span class="cm">,</span> <span class="i">$string</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p><b>CAVEAT</b>: When you run <code class="inline"><span class="i">$octets</span> = <span class="i">encode</span><span class="s">(</span><span class="q">&quot;utf8&quot;</span><span class="cm">,</span> <span class="i">$string</span><span class="s">)</span></code>
, then
$octets <i>might not be equal to</i> $string.  Though both contain the
same data, the UTF8 flag for $octets is <i>always</i> off.  When you
encode anything, the UTF8 flag on the result is always off, even when it
contains a completely valid utf8 string. See <a href="#The-UTF8-flag">The UTF8 flag</a> below.</p>
<p>If the $string is <code class="inline"><a class="l_k" href="functions/undef.html">undef</a></code>, then <code class="inline"><a class="l_k" href="functions/undef.html">undef</a></code> is returned.</p>
<a name="decode"></a><h3>decode</h3>
<pre class="verbatim"><ol><li>  <span class="i">$string</span> = <span class="i">decode</span><span class="s">(</span><span class="w">ENCODING</span><span class="cm">,</span> <span class="w">OCTETS</span><span class="s">[</span><span class="cm">,</span> <a class="l_k" href="functions/CHECK.html">CHECK</a><span class="s">]</span><span class="s">)</span></li></ol></pre><p>This function returns the string that results from decoding the scalar
value <i>OCTETS</i>, assumed to be a sequence of octets in <i>ENCODING</i>, into
Perl's internal form.  As with encode(),
<i>ENCODING</i> can be either a canonical name or an alias. For encoding names
and aliases, see <a href="#Defining-Aliases">Defining Aliases</a>; for <i>CHECK</i>, see <a href="#Handling-Malformed-Data">Handling Malformed Data</a>.</p>
<p><b>CAVEAT</b>: the input scalar <i>OCTETS</i> might be modified in-place depending
on what is set in CHECK. See <a href="#LEAVE_SRC">LEAVE_SRC</a> if you want your inputs to be
left unchanged.</p>
<p>For example, to convert ISO-8859-1 data into a string in Perl's
internal format:</p>
<pre class="verbatim"><ol><li>  <span class="i">$string</span> = <span class="i">decode</span><span class="s">(</span><span class="q">&quot;iso-8859-1&quot;</span><span class="cm">,</span> <span class="i">$octets</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p><b>CAVEAT</b>: When you run <code class="inline"><span class="i">$string</span> = <span class="i">decode</span><span class="s">(</span><span class="q">&quot;utf8&quot;</span><span class="cm">,</span> <span class="i">$octets</span><span class="s">)</span></code>
, then $string
<i>might not be equal to</i> $octets.  Though both contain the same data, the
UTF8 flag for $string is on.  See <a href="#The-UTF8-flag">The UTF8 flag</a>
below.</p>
<p>If the $string is <code class="inline"><a class="l_k" href="functions/undef.html">undef</a></code>, then <code class="inline"><a class="l_k" href="functions/undef.html">undef</a></code> is returned.</p>
<a name="find_encoding"></a><h3>find_encoding</h3>
<pre class="verbatim"><ol><li>  <span class="s">[</span><span class="i">$obj</span> =<span class="s">]</span> <span class="i">find_encoding</span><span class="s">(</span><span class="w">ENCODING</span><span class="s">)</span></li></ol></pre><p>Returns the <i>encoding object</i> corresponding to <i>ENCODING</i>.  Returns
<code class="inline"><a class="l_k" href="functions/undef.html">undef</a></code> if no matching <i>ENCODING</i> is find.  The returned object is
what does the actual encoding or decoding.</p>
<pre class="verbatim"><ol><li>  <span class="i">$utf8</span> = <span class="i">decode</span><span class="s">(</span><span class="i">$name</span><span class="cm">,</span> <span class="i">$bytes</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>is in fact</p>
<pre class="verbatim"><ol><li>    <span class="i">$utf8</span> = <a class="l_k" href="functions/do.html">do</a> <span class="s">{</span></li><li>        <span class="i">$obj</span> = <span class="i">find_encoding</span><span class="s">(</span><span class="i">$name</span><span class="s">)</span><span class="sc">;</span></li><li>        <span class="w">croak</span> <span class="q">qq(encoding &quot;$name&quot; not found)</span> <a class="l_k" href="functions/unless.html">unless</a> <a class="l_k" href="functions/ref.html">ref</a> <span class="i">$obj</span><span class="sc">;</span></li><li>        <span class="i">$obj</span><span class="i">-&gt;decode</span><span class="s">(</span><span class="i">$bytes</span><span class="s">)</span><span class="sc">;</span></li><li>    <span class="s">}</span><span class="sc">;</span></li></ol></pre><p>with more error checking.</p>
<p>You can therefore save time by reusing this object as follows;</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">$enc</span> = <span class="i">find_encoding</span><span class="s">(</span><span class="q">&quot;iso-8859-1&quot;</span><span class="s">)</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/while.html">while</a><span class="s">(</span>&lt;&gt;<span class="s">)</span> <span class="s">{</span></li><li>        <a class="l_k" href="functions/my.html">my</a> <span class="i">$utf8</span> = <span class="i">$enc</span><span class="i">-&gt;decode</span><span class="s">(</span><span class="i">$_</span><span class="s">)</span><span class="sc">;</span></li><li>        ... <span class="c"># now do something with $utf8;</span></li><li>    <span class="s">}</span></li></ol></pre><p>Besides <a href="#decode">decode</a> and <a href="#encode">encode</a>, other methods are
available as well.  For instance, <code class="inline"><span class="i">name</span><span class="s">(</span><span class="s">)</span></code>
 returns the canonical
name of the encoding object.</p>
<pre class="verbatim"><ol><li>  <span class="i">find_encoding</span><span class="s">(</span><span class="q">&quot;latin1&quot;</span><span class="s">)</span><span class="i">-&gt;name</span><span class="sc">;</span> <span class="c"># iso-8859-1</span></li></ol></pre><p>See <a href="Encode/Encoding.html">Encode::Encoding</a> for details.</p>
<a name="find_mime_encoding"></a><h3>find_mime_encoding</h3>
<pre class="verbatim"><ol><li>  <span class="s">[</span><span class="i">$obj</span> =<span class="s">]</span> <span class="i">find_mime_encoding</span><span class="s">(</span><span class="w">MIME_ENCODING</span><span class="s">)</span></li></ol></pre><p>Returns the <i>encoding object</i> corresponding to <i>MIME_ENCODING</i>.  Acts
same as <code class="inline"><span class="i">find_encoding</span><span class="s">(</span><span class="s">)</span></code>
 but <code class="inline"><span class="i">mime_name</span><span class="s">(</span><span class="s">)</span></code>
 of returned object must
match to <i>MIME_ENCODING</i>.  So as opposite of <code class="inline"><span class="i">find_encoding</span><span class="s">(</span><span class="s">)</span></code>

canonical names and aliases are not used when searching for object.</p>
<pre class="verbatim"><ol><li>    <span class="i">find_mime_encoding</span><span class="s">(</span><span class="q">&quot;utf8&quot;</span><span class="s">)</span><span class="sc">;</span> <span class="c"># returns undef because &quot;utf8&quot; is not valid I&lt;MIME_ENCODING&gt;</span></li><li>    <span class="i">find_mime_encoding</span><span class="s">(</span><span class="q">&quot;utf-8&quot;</span><span class="s">)</span><span class="sc">;</span> <span class="c"># returns encode object &quot;utf-8-strict&quot;</span></li><li>    <span class="i">find_mime_encoding</span><span class="s">(</span><span class="q">&quot;UTF-8&quot;</span><span class="s">)</span><span class="sc">;</span> <span class="c"># same as &quot;utf-8&quot; because I&lt;MIME_ENCODING&gt; is case insensitive</span></li><li>    <span class="i">find_mime_encoding</span><span class="s">(</span><span class="q">&quot;utf-8-strict&quot;</span><span class="s">)</span><span class="sc">;</span> <span class="w">returns</span> <a class="l_k" href="functions/undef.html">undef</a> <span class="w">because</span> <span class="q">&quot;utf-8-strict&quot;</span> <span class="w">is</span> <a class="l_k" href="functions/not.html">not</a> <span class="w">valid</span> <span class="w">I</span><span class="q">&lt;MIME_ENCODING&gt;</span></li></ol></pre><a name="from_to"></a><h3>from_to</h3>
<pre class="verbatim"><ol><li>  <span class="s">[</span><span class="i">$length</span> =<span class="s">]</span> <span class="i">from_to</span><span class="s">(</span><span class="i">$octets</span><span class="cm">,</span> <span class="w">FROM_ENC</span><span class="cm">,</span> <span class="w">TO_ENC</span> <span class="s">[</span><span class="cm">,</span> <a class="l_k" href="functions/CHECK.html">CHECK</a><span class="s">]</span><span class="s">)</span></li></ol></pre><p>Converts <i>in-place</i> data between two encodings. The data in $octets
must be encoded as octets and <i>not</i> as characters in Perl's internal
format. For example, to convert ISO-8859-1 data into Microsoft's CP1250
encoding:</p>
<pre class="verbatim"><ol><li>  <span class="i">from_to</span><span class="s">(</span><span class="i">$octets</span><span class="cm">,</span> <span class="q">&quot;iso-8859-1&quot;</span><span class="cm">,</span> <span class="q">&quot;cp1250&quot;</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>and to convert it back:</p>
<pre class="verbatim"><ol><li>  <span class="i">from_to</span><span class="s">(</span><span class="i">$octets</span><span class="cm">,</span> <span class="q">&quot;cp1250&quot;</span><span class="cm">,</span> <span class="q">&quot;iso-8859-1&quot;</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>Because the conversion happens in place, the data to be
converted cannot be a string constant: it must be a scalar variable.</p>
<p><code class="inline"><span class="i">from_to</span><span class="s">(</span><span class="s">)</span></code>
 returns the length of the converted string in octets on success,
and <code class="inline"><a class="l_k" href="functions/undef.html">undef</a></code> on error.</p>
<p><b>CAVEAT</b>: The following operations may look the same, but are not:</p>
<pre class="verbatim"><ol><li>  <span class="i">from_to</span><span class="s">(</span><span class="i">$data</span><span class="cm">,</span> <span class="q">&quot;iso-8859-1&quot;</span><span class="cm">,</span> <span class="q">&quot;utf8&quot;</span><span class="s">)</span><span class="sc">;</span> <span class="c">#1</span></li><li>  <span class="i">$data</span> = <span class="i">decode</span><span class="s">(</span><span class="q">&quot;iso-8859-1&quot;</span><span class="cm">,</span> <span class="i">$data</span><span class="s">)</span><span class="sc">;</span>  <span class="c">#2</span></li></ol></pre><p>Both #1 and #2 make $data consist of a completely valid UTF-8 string,
but only #2 turns the UTF8 flag on.  #1 is equivalent to:</p>
<pre class="verbatim"><ol><li>  <span class="i">$data</span> = <span class="i">encode</span><span class="s">(</span><span class="q">&quot;utf8&quot;</span><span class="cm">,</span> <span class="i">decode</span><span class="s">(</span><span class="q">&quot;iso-8859-1&quot;</span><span class="cm">,</span> <span class="i">$data</span><span class="s">)</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>See <a href="#The-UTF8-flag">The UTF8 flag</a> below.</p>
<p>Also note that:</p>
<pre class="verbatim"><ol><li>  <span class="i">from_to</span><span class="s">(</span><span class="i">$octets</span><span class="cm">,</span> <span class="i">$from</span><span class="cm">,</span> <span class="i">$to</span><span class="cm">,</span> <span class="i">$check</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>is equivalent to:</p>
<pre class="verbatim"><ol><li>  <span class="i">$octets</span> = <span class="i">encode</span><span class="s">(</span><span class="i">$to</span><span class="cm">,</span> <span class="i">decode</span><span class="s">(</span><span class="i">$from</span><span class="cm">,</span> <span class="i">$octets</span><span class="s">)</span><span class="cm">,</span> <span class="i">$check</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>Yes, it does <i>not</i> respect the $check during decoding.  It is
deliberately done that way.  If you need minute control, use <code class="inline"><span class="w">decode</span></code>

followed by <code class="inline"><span class="w">encode</span></code>
 as follows:</p>
<pre class="verbatim"><ol><li>  <span class="i">$octets</span> = <span class="i">encode</span><span class="s">(</span><span class="i">$to</span><span class="cm">,</span> <span class="i">decode</span><span class="s">(</span><span class="i">$from</span><span class="cm">,</span> <span class="i">$octets</span><span class="cm">,</span> <span class="i">$check_from</span><span class="s">)</span><span class="cm">,</span> <span class="i">$check_to</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><a name="encode_utf8"></a><h3>encode_utf8</h3>
<pre class="verbatim"><ol><li>  <span class="i">$octets</span> = <span class="i">encode_utf8</span><span class="s">(</span><span class="i">$string</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>Equivalent to <code class="inline"><span class="i">$octets</span> = <span class="i">encode</span><span class="s">(</span><span class="q">&quot;utf8&quot;</span><span class="cm">,</span> <span class="i">$string</span><span class="s">)</span></code>
.  The characters in
$string are encoded in Perl's internal format, and the result is returned
as a sequence of octets.  Because all possible characters in Perl have a
(loose, not strict) UTF-8 representation, this function cannot fail.</p>
<a name="decode_utf8"></a><h3>decode_utf8</h3>
<pre class="verbatim"><ol><li>  <span class="i">$string</span> = <span class="i">decode_utf8</span><span class="s">(</span><span class="i">$octets</span> [<span class="cm">,</span> <a class="l_k" href="functions/CHECK.html">CHECK</a>]<span class="s">)</span><span class="sc">;</span></li></ol></pre><p>Equivalent to <code class="inline"><span class="i">$string</span> = <span class="i">decode</span><span class="s">(</span><span class="q">&quot;utf8&quot;</span><span class="cm">,</span> <span class="i">$octets</span> [<span class="cm">,</span> CHECK]<span class="s">)</span></code>
.
The sequence of octets represented by $octets is decoded
from UTF-8 into a sequence of logical characters.
Because not all sequences of octets are valid UTF-8,
it is quite possible for this function to fail.
For CHECK, see <a href="#Handling-Malformed-Data">Handling Malformed Data</a>.</p>
<p><b>CAVEAT</b>: the input <i>$octets</i> might be modified in-place depending on
what is set in CHECK. See <a href="#LEAVE_SRC">LEAVE_SRC</a> if you want your inputs to be
left unchanged.</p>
<a name="Listing-available-encodings"></a><h2>Listing available encodings</h2>
<pre class="verbatim"><ol><li>  <a class="l_k" href="functions/use.html">use</a> <span class="w">Encode</span><span class="sc">;</span></li><li>  <span class="i">@list</span> = <span class="w">Encode</span><span class="w">-&gt;encodings</span><span class="s">(</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>Returns a list of canonical names of available encodings that have already
been loaded.  To get a list of all available encodings including those that
have not yet been loaded, say:</p>
<pre class="verbatim"><ol><li>  <span class="i">@all_encodings</span> = <span class="w">Encode</span><span class="w">-&gt;encodings</span><span class="s">(</span><span class="q">&quot;:all&quot;</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>Or you can give the name of a specific module:</p>
<pre class="verbatim"><ol><li>  <span class="i">@with_jp</span> = <span class="w">Encode</span><span class="w">-&gt;encodings</span><span class="s">(</span><span class="q">&quot;Encode::JP&quot;</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>When "<code class="inline"><span class="w">::</span></code>
" is not in the name, "<code class="inline"><span class="w">Encode::</span></code>
" is assumed.</p>
<pre class="verbatim"><ol><li>  <span class="i">@ebcdic</span> = <span class="w">Encode</span><span class="w">-&gt;encodings</span><span class="s">(</span><span class="q">&quot;EBCDIC&quot;</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>To find out in detail which encodings are supported by this package,
see <a href="Encode/Supported.html">Encode::Supported</a>.</p>
<a name="Defining-Aliases"></a><h2>Defining Aliases</h2>
<p>To add a new alias to a given encoding, use:</p>
<pre class="verbatim"><ol><li>  <a class="l_k" href="functions/use.html">use</a> <span class="w">Encode</span><span class="sc">;</span></li><li>  <a class="l_k" href="functions/use.html">use</a> <span class="w">Encode::Alias</span><span class="sc">;</span></li><li>  <span class="i">define_alias</span><span class="s">(</span><span class="w">NEWNAME</span> <span class="cm">=&gt;</span> <span class="w">ENCODING</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>After that, <i>NEWNAME</i> can be used as an alias for <i>ENCODING</i>.
<i>ENCODING</i> may be either the name of an encoding or an
<i>encoding object</i>.</p>
<p>Before you do that, first make sure the alias is nonexistent using
<code class="inline"><span class="i">resolve_alias</span><span class="s">(</span><span class="s">)</span></code>
, which returns the canonical name thereof.
For example:</p>
<pre class="verbatim"><ol><li>  Encode::resolve_alias("latin1") eq "iso-8859-1" # true</li><li>  Encode::resolve_alias("iso-8859-12")   # false; nonexistent</li><li>  Encode::resolve_alias($name) eq $name  # true if $name is canonical</li></ol></pre><p><code class="inline"><span class="i">resolve_alias</span><span class="s">(</span><span class="s">)</span></code>
 does not need <code class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="w">Encode::Alias</span></code>
; it can be
imported via <code class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="w">Encode</span> <span class="q">qw(resolve_alias)</span></code>
.</p>
<p>See <a href="Encode/Alias.html">Encode::Alias</a> for details.</p>
<a name="Finding-IANA-Character-Set-Registry-names"></a><h2>Finding IANA Character Set Registry names</h2>
<p>The canonical name of a given encoding does not necessarily agree with
IANA Character Set Registry, commonly seen as <code class="inline">Content-Type:
text/plain; charset=<i>WHATEVER</i></code>.  For most cases, the canonical name
works, but sometimes it does not, most notably with "utf-8-strict".</p>
<p>As of <code class="inline"><span class="w">Encode</span></code>
 version 2.21, a new method <code class="inline"><span class="i">mime_name</span><span class="s">(</span><span class="s">)</span></code>
 is therefore added.</p>
<pre class="verbatim"><ol><li>  <a class="l_k" href="functions/use.html">use</a> <span class="w">Encode</span><span class="sc">;</span></li><li>  <a class="l_k" href="functions/my.html">my</a> <span class="i">$enc</span> = <span class="i">find_encoding</span><span class="s">(</span><span class="q">&quot;UTF-8&quot;</span><span class="s">)</span><span class="sc">;</span></li><li>  <a class="l_k" href="functions/warn.html">warn</a> <span class="i">$enc</span><span class="i">-&gt;name</span><span class="sc">;</span>      <span class="c"># utf-8-strict</span></li><li>  <a class="l_k" href="functions/warn.html">warn</a> <span class="i">$enc</span><span class="i">-&gt;mime_name</span><span class="sc">;</span> <span class="c"># UTF-8</span></li></ol></pre><p>See also:  <a href="Encode/Encoding.html">Encode::Encoding</a></p>
<a name="Encoding-via-PerlIO"></a><h1>Encoding via PerlIO</h1>
<p>If your perl supports <code class="inline"><span class="w">PerlIO</span></code>
 (which is the default), you can use a
<code class="inline"><span class="w">PerlIO</span></code>
 layer to decode and encode directly via a filehandle.  The
following two examples are fully identical in functionality:</p>
<pre class="verbatim"><ol><li>  <span class="c">### Version 1 via PerlIO</span></li><li>    <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><span class="w">INPUT</span><span class="cm">,</span>  <span class="q">&quot;&lt; :encoding(shiftjis)&quot;</span><span class="cm">,</span> <span class="i">$infile</span><span class="s">)</span></li><li>        || <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;Can&#39;t open &lt; $infile for reading: $!&quot;</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><span class="w">OUTPUT</span><span class="cm">,</span> <span class="q">&quot;&gt; :encoding(euc-jp)&quot;</span><span class="cm">,</span>  <span class="i">$outfile</span><span class="s">)</span></li><li>        || <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;Can&#39;t open &gt; $output for writing: $!&quot;</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/while.html">while</a> <span class="s">(</span><span class="q">&lt;INPUT&gt;</span><span class="s">)</span> <span class="s">{</span>   <span class="c"># auto decodes $_</span></li><li>        <a class="l_k" href="functions/print.html">print</a> <span class="i">OUTPUT</span><span class="sc">;</span>   <span class="c"># auto encodes $_</span></li><li>    <span class="s">}</span></li><li>    <a class="l_k" href="functions/close.html">close</a><span class="s">(</span><span class="w">INPUT</span><span class="s">)</span>   || <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;can&#39;t close $infile: $!&quot;</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/close.html">close</a><span class="s">(</span><span class="w">OUTPUT</span><span class="s">)</span>  || <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;can&#39;t close $outfile: $!&quot;</span><span class="sc">;</span></li><li></li><li>  <span class="c">### Version 2 via from_to()</span></li><li>    <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><span class="w">INPUT</span><span class="cm">,</span>  <span class="q">&quot;&lt; :raw&quot;</span><span class="cm">,</span> <span class="i">$infile</span><span class="s">)</span></li><li>        || <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;Can&#39;t open &lt; $infile for reading: $!&quot;</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><span class="w">OUTPUT</span><span class="cm">,</span> <span class="q">&quot;&gt; :raw&quot;</span><span class="cm">,</span>  <span class="i">$outfile</span><span class="s">)</span></li><li>        || <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;Can&#39;t open &gt; $output for writing: $!&quot;</span><span class="sc">;</span></li><li></li><li>    <a class="l_k" href="functions/while.html">while</a> <span class="s">(</span><span class="q">&lt;INPUT&gt;</span><span class="s">)</span> <span class="s">{</span></li><li>        <span class="i">from_to</span><span class="s">(</span><span class="i">$_</span><span class="cm">,</span> <span class="q">&quot;shiftjis&quot;</span><span class="cm">,</span> <span class="q">&quot;euc-jp&quot;</span><span class="cm">,</span> <span class="n">1</span><span class="s">)</span><span class="sc">;</span>  <span class="c"># switch encoding</span></li><li>        <a class="l_k" href="functions/print.html">print</a> <span class="i">OUTPUT</span><span class="sc">;</span>   <span class="c"># emit raw (but properly encoded) data</span></li><li>    <span class="s">}</span></li><li>    <a class="l_k" href="functions/close.html">close</a><span class="s">(</span><span class="w">INPUT</span><span class="s">)</span>   || <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;can&#39;t close $infile: $!&quot;</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/close.html">close</a><span class="s">(</span><span class="w">OUTPUT</span><span class="s">)</span>  || <a class="l_k" href="functions/die.html">die</a> <span class="q">&quot;can&#39;t close $outfile: $!&quot;</span><span class="sc">;</span></li></ol></pre><p>In the first version above, you let the appropriate encoding layer
handle the conversion.  In the second, you explicitly translate
from one encoding to the other.</p>
<p>Unfortunately, it may be that encodings are not <code class="inline"><span class="w">PerlIO</span></code>
-savvy.  You can check
to see whether your encoding is supported by <code class="inline"><span class="w">PerlIO</span></code>
 by invoking the
<code class="inline"><span class="w">perlio_ok</span></code>
 method on it:</p>
<pre class="verbatim"><ol><li>  <span class="i">Encode::perlio_ok</span><span class="s">(</span><span class="q">&quot;hz&quot;</span><span class="s">)</span><span class="sc">;</span>             <span class="c"># false</span></li><li>  <span class="i">find_encoding</span><span class="s">(</span><span class="q">&quot;euc-cn&quot;</span><span class="s">)</span><span class="i">-&gt;perlio_ok</span><span class="sc">;</span>  <span class="c"># true wherever PerlIO is available</span></li><li></li><li>  <a class="l_k" href="functions/use.html">use</a> <span class="w">Encode</span> <span class="q">qw(perlio_ok)</span><span class="sc">;</span>            <span class="c"># imported upon request</span></li><li>  <span class="i">perlio_ok</span><span class="s">(</span><span class="q">&quot;euc-jp&quot;</span><span class="s">)</span></li></ol></pre><p>Fortunately, all encodings that come with <code class="inline"><span class="w">Encode</span></code>
 core are <code class="inline"><span class="w">PerlIO</span></code>
-savvy
except for <code class="inline"><span class="w">hz</span></code>
 and <code class="inline"><span class="w">ISO</span>-<span class="n">2022</span>-<span class="w">kr</span></code>
.  For the gory details, see
<a href="Encode/Encoding.html">Encode::Encoding</a> and <a href="Encode/PerlIO.html">Encode::PerlIO</a>.</p>
<a name="Handling-Malformed-Data"></a><h1>Handling Malformed Data</h1>
<p>The optional <i>CHECK</i> argument tells <code class="inline"><span class="w">Encode</span></code>
 what to do when
encountering malformed data.  Without <i>CHECK</i>, <code class="inline"><span class="w">Encode::FB_DEFAULT</span></code>

(== 0) is assumed.</p>
<p>As of version 2.12, <code class="inline"><span class="w">Encode</span></code>
 supports coderef values for <code class="inline">CHECK</code>
;
see below.</p>
<p><b>NOTE:</b> Not all encodings support this feature.
Some encodings ignore the <i>CHECK</i> argument.  For example,
<a href="Encode/Unicode.html">Encode::Unicode</a> ignores <i>CHECK</i> and it always croaks on error.</p>
<a name="List-of-_CHECK_-values"></a><h2>List of <i>CHECK</i> values</h2>
<a name="FB_DEFAULT"></a><h3>FB_DEFAULT</h3>
<pre class="verbatim"><ol><li>  <span class="w">I</span><span class="q">&lt;CHECK&gt;</span> = <span class="w">Encode::FB_DEFAULT</span> <span class="s">(</span> == <span class="n">0</span><span class="s">)</span></li></ol></pre><p>If <i>CHECK</i> is 0, encoding and decoding replace any malformed character
with a <i>substitution character</i>.  When you encode, <i>SUBCHAR</i> is used.
When you decode, the Unicode REPLACEMENT CHARACTER, code point U+FFFD, is
used.  If the data is supposed to be UTF-8, an optional lexical warning of
warning category <code class="inline"><span class="q">&quot;utf8&quot;</span></code>
 is given.</p>
<a name="FB_CROAK"></a><h3>FB_CROAK</h3>
<pre class="verbatim"><ol><li>  <span class="w">I</span><span class="q">&lt;CHECK&gt;</span> = <span class="w">Encode::FB_CROAK</span> <span class="s">(</span> == <span class="n">1</span><span class="s">)</span></li></ol></pre><p>If <i>CHECK</i> is 1, methods immediately die with an error
message.  Therefore, when <i>CHECK</i> is 1, you should trap
exceptions with <code class="inline"><a class="l_k" href="functions/eval.html">eval{}</a></code>, unless you really want to let it <code class="inline"><a class="l_k" href="functions/die.html">die</a></code>.</p>
<a name="FB_QUIET"></a><h3>FB_QUIET</h3>
<pre class="verbatim"><ol><li>  <span class="w">I</span><span class="q">&lt;CHECK&gt;</span> = <span class="w">Encode::FB_QUIET</span></li></ol></pre><p>If <i>CHECK</i> is set to <code class="inline"><span class="w">Encode::FB_QUIET</span></code>
, encoding and decoding immediately
return the portion of the data that has been processed so far when an
error occurs. The data argument is overwritten with everything
after that point; that is, the unprocessed portion of the data.  This is
handy when you have to call <code class="inline"><span class="w">decode</span></code>
 repeatedly in the case where your
source data may contain partial multi-byte character sequences,
(that is, you are reading with a fixed-width buffer). Here's some sample
code to do exactly that:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/my.html">my</a><span class="s">(</span><span class="i">$buffer</span><span class="cm">,</span> <span class="i">$string</span><span class="s">)</span> = <span class="s">(</span><span class="q">&quot;&quot;</span><span class="cm">,</span> <span class="q">&quot;&quot;</span><span class="s">)</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/while.html">while</a> <span class="s">(</span><a class="l_k" href="functions/read.html">read</a><span class="s">(</span><span class="i">$fh</span><span class="cm">,</span> <span class="i">$buffer</span><span class="cm">,</span> <span class="n">256</span><span class="cm">,</span> <a class="l_k" href="functions/length.html">length</a><span class="s">(</span><span class="i">$buffer</span><span class="s">)</span><span class="s">)</span><span class="s">)</span> <span class="s">{</span></li><li>        <span class="i">$string</span> .= <span class="i">decode</span><span class="s">(</span><span class="i">$encoding</span><span class="cm">,</span> <span class="i">$buffer</span><span class="cm">,</span> <span class="w">Encode::FB_QUIET</span><span class="s">)</span><span class="sc">;</span></li><li>        <span class="c"># $buffer now contains the unprocessed partial character</span></li><li>    <span class="s">}</span></li></ol></pre><a name="FB_WARN"></a><h3>FB_WARN</h3>
<pre class="verbatim"><ol><li>  <span class="w">I</span><span class="q">&lt;CHECK&gt;</span> = <span class="w">Encode::FB_WARN</span></li></ol></pre><p>This is the same as <code class="inline"><span class="w">FB_QUIET</span></code>
 above, except that instead of being silent
on errors, it issues a warning.  This is handy for when you are debugging.</p>
<a name="FB_PERLQQ-FB_HTMLCREF-FB_XMLCREF"></a><h3>FB_PERLQQ FB_HTMLCREF FB_XMLCREF</h3>
<ul>
<li><a name="perlqq-mode-(_CHECK_-%3d-Encode%3a%3aFB_PERLQQ)"></a><b>perlqq mode (<i>CHECK</i> = Encode::FB_PERLQQ)</b>
</li>
<li><a name="HTML-charref-mode-(_CHECK_-%3d-Encode%3a%3aFB_HTMLCREF)"></a><b>HTML charref mode (<i>CHECK</i> = Encode::FB_HTMLCREF)</b>
</li>
<li><a name="XML-charref-mode-(_CHECK_-%3d-Encode%3a%3aFB_XMLCREF)"></a><b>XML charref mode (<i>CHECK</i> = Encode::FB_XMLCREF)</b>
</li>
</ul>
<p>For encodings that are implemented by the <code class="inline"><span class="w">Encode::XS</span></code>
 module, <code class="inline">CHECK</code>
 <code class="inline">==</code>

<code class="inline"><span class="w">Encode::FB_PERLQQ</span></code>
 puts <code class="inline"><span class="w">encode</span></code>
 and <code class="inline"><span class="w">decode</span></code>
 into <code class="inline"><span class="w">perlqq</span></code>
 fallback mode.</p>
<p>When you decode, <code class="inline">\x<i>HH</i></code> is inserted for a malformed character, where
<i>HH</i> is the hex representation of the octet that could not be decoded to
utf8.  When you encode, <code class="inline">\x{<i>HHHH</i>}</code> will be inserted, where <i>HHHH</i> is
the Unicode code point (in any number of hex digits) of the character that
cannot be found in the character repertoire of the encoding.</p>
<p>The HTML/XML character reference modes are about the same. In place of
<code class="inline">\x{<i>HHHH</i>}</code>, HTML uses <code class="inline">&amp;#<i>NNN</i>;</code> where <i>NNN</i> is a decimal number, and
XML uses <code class="inline">&amp;#x<i>HHHH</i>;</code> where <i>HHHH</i> is the hexadecimal number.</p>
<p>In <code class="inline"><span class="w">Encode</span></code>
 2.10 or later, <code class="inline"><span class="w">LEAVE_SRC</span></code>
 is also implied.</p>
<a name="The-bitmask"></a><h3>The bitmask</h3>
<p>These modes are all actually set via a bitmask.  Here is how the <code class="inline">FB_<i>XXX</i></code>
constants are laid out.  You can import the <code class="inline">FB_<i>XXX</i></code> constants via
<code class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="w">Encode</span> <span class="q">qw(:fallbacks)</span></code>
, and you can import the generic bitmask
constants via <code class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="w">Encode</span> <span class="q">qw(:fallback_all)</span></code>
.</p>
<pre class="verbatim"><ol><li>                     FB_DEFAULT FB_CROAK FB_QUIET FB_WARN  FB_PERLQQ</li><li> DIE_ON_ERR    0x0001             X</li><li> WARN_ON_ERR   0x0002                               X</li><li> RETURN_ON_ERR 0x0004                      X        X</li><li> LEAVE_SRC     0x0008                                        X</li><li> PERLQQ        0x0100                                        X</li><li> HTMLCREF      0x0200</li><li> XMLCREF       0x0400</li></ol></pre><a name="LEAVE_SRC"></a><h3>LEAVE_SRC</h3>
<pre class="verbatim"><ol><li>  <span class="w">Encode::LEAVE_SRC</span></li></ol></pre><p>If the <code class="inline"><span class="w">Encode::LEAVE_SRC</span></code>
 bit is <i>not</i> set but <i>CHECK</i> is set, then the
source string to encode() or decode() will be overwritten in place.
If you're not interested in this, then bitwise-OR it with the bitmask.</p>
<a name="coderef-for-CHECK"></a><h2>coderef for CHECK</h2>
<p>As of <code class="inline"><span class="w">Encode</span></code>
 2.12, <code class="inline">CHECK</code>
 can also be a code reference which takes the
ordinal value of the unmapped character as an argument and returns
octets that represent the fallback character.  For instance:</p>
<pre class="verbatim"><ol><li>  <span class="i">$ascii</span> = <span class="i">encode</span><span class="s">(</span><span class="q">&quot;ascii&quot;</span><span class="cm">,</span> <span class="i">$utf8</span><span class="cm">,</span> <a class="l_k" href="functions/sub.html">sub</a><span class="s">{</span> <a class="l_k" href="functions/sprintf.html">sprintf</a> <span class="q">&quot;&lt;U+%04X&gt;&quot;</span><span class="cm">,</span> <a class="l_k" href="functions/shift.html">shift</a> <span class="s">}</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>Acts like <code class="inline"><span class="w">FB_PERLQQ</span></code>
 but U+<i>XXXX</i> is used instead of <code class="inline">\x{<i>XXXX</i>}</code>.</p>
<p>Even the fallback for <code class="inline"><span class="w">decode</span></code>
 must return octets, which are
then decoded with the character encoding that <code class="inline"><span class="w">decode</span></code>
 accepts. So for
example if you wish to decode octets as UTF-8, and use ISO-8859-15 as
a fallback for bytes that are not valid UTF-8, you could write</p>
<pre class="verbatim"><ol><li>    <span class="i">$str</span> = <span class="w">decode</span> <span class="q">&#39;UTF-8&#39;</span><span class="cm">,</span> <span class="i">$octets</span><span class="cm">,</span> <a class="l_k" href="functions/sub.html">sub</a> <span class="s">{</span></li><li>        <a class="l_k" href="functions/my.html">my</a> <span class="i">$tmp</span> = <a class="l_k" href="functions/chr.html">chr</a> <a class="l_k" href="functions/shift.html">shift</a><span class="sc">;</span></li><li>        <span class="w">from_to</span> <span class="i">$tmp</span><span class="cm">,</span> <span class="q">&#39;ISO-8859-15&#39;</span><span class="cm">,</span> <span class="q">&#39;UTF-8&#39;</span><span class="sc">;</span></li><li>        <a class="l_k" href="functions/return.html">return</a> <span class="i">$tmp</span><span class="sc">;</span></li><li>    <span class="s">}</span><span class="sc">;</span></li></ol></pre><a name="Defining-Encodings"></a><h1>Defining Encodings</h1>
<p>To define a new encoding, use:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/use.html">use</a> <span class="w">Encode</span> <span class="q">qw(define_encoding)</span><span class="sc">;</span></li><li>    <span class="i">define_encoding</span><span class="s">(</span><span class="i">$object</span><span class="cm">,</span> <span class="w">CANONICAL_NAME</span> <span class="s">[</span><span class="cm">,</span> <span class="w">alias</span>...<span class="s">]</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p><i>CANONICAL_NAME</i> will be associated with <i>$object</i>.  The object
should provide the interface described in <a href="Encode/Encoding.html">Encode::Encoding</a>.
If more than two arguments are provided, additional
arguments are considered aliases for <i>$object</i>.</p>
<p>See <a href="Encode/Encoding.html">Encode::Encoding</a> for details.</p>
<a name="The-UTF8-flag"></a><h1>The UTF8 flag</h1>
<p>Before the introduction of Unicode support in Perl, The <code class="inline">eq</code>
 operator
just compared the strings represented by two scalars. Beginning with
Perl 5.8, <code class="inline">eq</code>
 compares two strings with simultaneous consideration of
<i>the UTF8 flag</i>. To explain why we made it so, I quote from page 402 of
<i>Programming Perl, 3rd ed.</i></p>
<ul>
<li><a name="Goal-%231%3a"></a><b>Goal #1:</b>
<p>Old byte-oriented programs should not spontaneously break on the old
byte-oriented data they used to work on.</p>
</li>
<li><a name="Goal-%232%3a"></a><b>Goal #2:</b>
<p>Old byte-oriented programs should magically start working on the new
character-oriented data when appropriate.</p>
</li>
<li><a name="Goal-%233%3a"></a><b>Goal #3:</b>
<p>Programs should run just as fast in the new character-oriented mode
as in the old byte-oriented mode.</p>
</li>
<li><a name="Goal-%234%3a"></a><b>Goal #4:</b>
<p>Perl should remain one language, rather than forking into a
byte-oriented Perl and a character-oriented Perl.</p>
</li>
</ul>
<p>When <i>Programming Perl, 3rd ed.</i> was written, not even Perl 5.6.0 had been
born yet, many features documented in the book remained unimplemented for a
long time.  Perl 5.8 corrected much of this, and the introduction of the
UTF8 flag is one of them.  You can think of there being two fundamentally
different kinds of strings and string-operations in Perl: one a
byte-oriented mode  for when the internal UTF8 flag is off, and the other a
character-oriented mode for when the internal UTF8 flag is on.</p>
<p>Here is how <code class="inline"><span class="w">Encode</span></code>
 handles the UTF8 flag.</p>
<ul>
<li>
<p>When you <i>encode</i>, the resulting UTF8 flag is always <b>off</b>.</p>
</li>
<li>
<p>When you <i>decode</i>, the resulting UTF8 flag is <b>on</b>--<i>unless</i> you can
unambiguously represent data.  Here is what we mean by "unambiguously".
After <code class="inline"><span class="i">$utf8</span> = <span class="i">decode</span><span class="s">(</span><span class="q">&quot;foo&quot;</span><span class="cm">,</span> <span class="i">$octet</span><span class="s">)</span></code>
,</p>
<pre class="verbatim"><ol><li>  When $octet is...   The UTF8 flag in $utf8 is</li><li>  ---------------------------------------------</li><li>  In ASCII only (or EBCDIC only)            OFF</li><li>  In ISO-8859-1                              ON</li><li>  In any other Encoding                      ON</li><li>  ---------------------------------------------</li></ol></pre><p>As you see, there is one exception: in ASCII.  That way you can assume
Goal #1.  And with <code class="inline"><span class="w">Encode</span></code>
, Goal #2 is assumed but you still have to be
careful in the cases mentioned in the <b>CAVEAT</b> paragraphs above.</p>
<p>This UTF8 flag is not visible in Perl scripts, exactly for the same reason
you cannot (or rather, you <i>don't have to</i>) see whether a scalar contains
a string, an integer, or a floating-point number.   But you can still peek
and poke these if you will.  See the next section.</p>
</li>
</ul>
<a name="Messing-with-Perl's-Internals"></a><h2>Messing with Perl's Internals</h2>
<p>The following API uses parts of Perl's internals in the current
implementation.  As such, they are efficient but may change in a future
release.</p>
<a name="is_utf8"></a><h3>is_utf8</h3>
<pre class="verbatim"><ol><li>  <span class="i">is_utf8</span><span class="s">(</span><span class="w">STRING</span> <span class="s">[</span><span class="cm">,</span> <a class="l_k" href="functions/CHECK.html">CHECK</a><span class="s">]</span><span class="s">)</span></li></ol></pre><p>[INTERNAL] Tests whether the UTF8 flag is turned on in the <i>STRING</i>.
If <i>CHECK</i> is true, also checks whether <i>STRING</i> contains well-formed
UTF-8.  Returns true if successful, false otherwise.</p>
<p>As of Perl 5.8.1, <a href="utf8.html">utf8</a> also has the <code class="inline"><span class="w">utf8::is_utf8</span></code>
 function.</p>
<a name="_utf8_on"></a><h3>_utf8_on</h3>
<pre class="verbatim"><ol><li>  <span class="i">_utf8_on</span><span class="s">(</span><span class="w">STRING</span><span class="s">)</span></li></ol></pre><p>[INTERNAL] Turns the <i>STRING</i>'s internal UTF8 flag <b>on</b>.  The <i>STRING</i>
is <i>not</i> checked for containing only well-formed UTF-8.  Do not use this
unless you <i>know with absolute certainty</i> that the STRING holds only
well-formed UTF-8.  Returns the previous state of the UTF8 flag (so please
don't treat the return value as indicating success or failure), or <code class="inline"><a class="l_k" href="functions/undef.html">undef</a></code>
if <i>STRING</i> is not a string.</p>
<p><b>NOTE</b>: For security reasons, this function does not work on tainted values.</p>
<a name="_utf8_off"></a><h3>_utf8_off</h3>
<pre class="verbatim"><ol><li>  <span class="i">_utf8_off</span><span class="s">(</span><span class="w">STRING</span><span class="s">)</span></li></ol></pre><p>[INTERNAL] Turns the <i>STRING</i>'s internal UTF8 flag <b>off</b>.  Do not use
frivolously.  Returns the previous state of the UTF8 flag, or <code class="inline"><a class="l_k" href="functions/undef.html">undef</a></code> if
<i>STRING</i> is not a string.  Do not treat the return value as indicative of
success or failure, because that isn't what it means: it is only the
previous setting.</p>
<p><b>NOTE</b>: For security reasons, this function does not work on tainted values.</p>
<a name="UTF-8-vs.-utf8-vs.-UTF8"></a><h1>UTF-8 vs. utf8 vs. UTF8</h1>
<pre class="verbatim"><ol><li>  ....We now view strings not as sequences of bytes, but as sequences</li><li>  of numbers in the range 0 .. 2**32-1 (or in the case of 64-bit</li><li>  computers, 0 .. 2**64-1) -- Programming Perl, 3rd ed.</li></ol></pre><p>That has historically been Perl's notion of UTF-8, as that is how UTF-8 was
first conceived by Ken Thompson when he invented it. However, thanks to
later revisions to the applicable standards, official UTF-8 is now rather
stricter than that. For example, its range is much narrower (0 .. 0x10_FFFF
to cover only 21 bits instead of 32 or 64 bits) and some sequences
are not allowed, like those used in surrogate pairs, the 31 non-character
code points 0xFDD0 .. 0xFDEF, the last two code points in <i>any</i> plane
(0x<i>XX</i>_FFFE and 0x<i>XX</i>_FFFF), all non-shortest encodings, etc.</p>
<p>The former default in which Perl would always use a loose interpretation of
UTF-8 has now been overruled:</p>
<pre class="verbatim"><ol><li>  <span class="j">From:</span> <span class="w">Larry</span> <span class="w">Wall</span> <span class="q">&lt;larry@wall.org&gt;</span></li><li>  <span class="w">Date</span><span class="co">:</span> <span class="w">December</span> <span class="n">04</span><span class="cm">,</span> <span class="n">2004</span> <span class="n">11</span><span class="co">:</span><span class="n">51</span><span class="co">:</span><span class="n">58</span> <span class="w">JST</span></li><li>  <span class="w">To</span><span class="co">:</span> <span class="w">perl</span>-<span class="w">unicode</span><span class="i">@perl</span>.<span class="w">org</span></li><li>  <span class="w">Subject</span><span class="co">:</span> <span class="w">Re</span><span class="co">:</span> <span class="w">Make</span> <span class="w">Encode</span>.<span class="w">pm</span> <span class="w">support</span> <span class="w">the</span> <span class="w">real</span> <span class="w">UTF</span>-<span class="n">8</span></li><li>  <span class="w">Message</span>-<span class="w">Id</span><span class="co">:</span> <span class="q">&lt;20041204025158.GA28754@wall.org&gt;</span></li><li></li><li>  <span class="w">On</span> <span class="w">Fri</span><span class="cm">,</span> <span class="w">Dec</span> <span class="n">03</span><span class="cm">,</span> <span class="n">2004</span> <span class="w">at</span> <span class="n">10</span><span class="co">:</span><span class="n">12</span><span class="co">:</span><span class="n">12</span><span class="w">PM</span> +<span class="n">0000</span><span class="cm">,</span> <span class="w">Tim</span> <span class="w">Bunce</span> <span class="w">wrote</span><span class="co">:</span></li><li>  <span class="co">:</span> <span class="w">I&#39;ve</span> <a class="l_k" href="functions/no.html">no</a> <span class="w">problem</span> <span class="w">with</span> <span class="q">&#39;utf8&#39;</span> <span class="w">being</span> <span class="w">perl&#39;s</span> <span class="w">unrestricted</span> <span class="w">uft8</span> <span class="w">encoding</span><span class="cm">,</span></li><li>  <span class="co">:</span> <span class="w">but</span> <span class="q">&quot;UTF-8&quot;</span> <span class="w">is</span> <span class="w">the</span> <span class="w">name</span> <span class="w">of</span> <span class="w">the</span> <span class="w">standard</span> <a class="l_k" href="functions/and.html">and</a> <span class="w">should</span> <span class="w">give</span> <span class="w">the</span></li><li>  <span class="co">:</span> <span class="w">corresponding</span> <span class="w">behaviour</span>.</li><li></li><li>  <span class="w">For</span> <span class="w">what</span> <span class="w">it&#39;s</span> <span class="w">worth</span><span class="cm">,</span> <span class="w">that&#39;s</span> <span class="w">how</span> <span class="w">I&#39;ve</span> <span class="w">always</span> <span class="w">kept</span> <span class="w">them</span> <span class="w">straight</span> <span class="w">in</span> <a class="l_k" href="functions/my.html">my</a></li><li>  <span class="w">head</span>.</li><li></li><li>  <span class="w">Also</span> <a class="l_k" href="functions/for.html">for</a> <span class="w">what</span> <span class="w">it&#39;s</span> <span class="w">worth</span><span class="cm">,</span> <span class="w">Perl</span> <span class="n">6</span> <span class="w">will</span> <span class="w">mostly</span> <span class="w">default</span> <span class="w">to</span> <span class="w">strict</span> <span class="w">but</span></li><li>  <span class="w">make</span> <span class="w">it</span> <span class="w">easy</span> <span class="w">to</span> switch <span class="w">back</span> <span class="w">to</span> <span class="w">lax</span>.</li><li></li><li>  <span class="w">Larry</span></li></ol></pre><p>Got that?  As of Perl 5.8.7, <b>"UTF-8"</b> means UTF-8 in its current
sense, which is conservative and strict and security-conscious, whereas
<b>"utf8"</b> means UTF-8 in its former sense, which was liberal and loose and
lax.  <code class="inline"><span class="w">Encode</span></code>
 version 2.10 or later thus groks this subtle but critically
important distinction between <code class="inline"><span class="q">&quot;UTF-8&quot;</span></code>
 and <code class="inline"><span class="q">&quot;utf8&quot;</span></code>
.</p>
<pre class="verbatim"><ol><li>  <span class="i">encode</span><span class="s">(</span><span class="q">&quot;utf8&quot;</span><span class="cm">,</span>  <span class="q">&quot;\x{FFFF_FFFF}&quot;</span><span class="cm">,</span> <span class="n">1</span><span class="s">)</span><span class="sc">;</span> <span class="c"># okay</span></li><li>  <span class="i">encode</span><span class="s">(</span><span class="q">&quot;UTF-8&quot;</span><span class="cm">,</span> <span class="q">&quot;\x{FFFF_FFFF}&quot;</span><span class="cm">,</span> <span class="n">1</span><span class="s">)</span><span class="sc">;</span> <span class="c"># croaks</span></li></ol></pre><p>In the <code class="inline"><span class="w">Encode</span></code>
 module, <code class="inline"><span class="q">&quot;UTF-8&quot;</span></code>
 is actually a canonical name for
<code class="inline"><span class="q">&quot;utf-8-strict&quot;</span></code>
.  That hyphen between the <code class="inline"><span class="q">&quot;UTF&quot;</span></code>
 and the <code class="inline"><span class="q">&quot;8&quot;</span></code>
 is
critical; without it, <code class="inline"><span class="w">Encode</span></code>
 goes "liberal" and (perhaps overly-)permissive:</p>
<pre class="verbatim"><ol><li>  <span class="i">find_encoding</span><span class="s">(</span><span class="q">&quot;UTF-8&quot;</span><span class="s">)</span><span class="i">-&gt;name</span> <span class="c"># is &#39;utf-8-strict&#39;</span></li><li>  <span class="i">find_encoding</span><span class="s">(</span><span class="q">&quot;utf-8&quot;</span><span class="s">)</span><span class="i">-&gt;name</span> <span class="c"># ditto. names are case insensitive</span></li><li>  <span class="i">find_encoding</span><span class="s">(</span><span class="q">&quot;utf_8&quot;</span><span class="s">)</span><span class="i">-&gt;name</span> <span class="c"># ditto. &quot;_&quot; are treated as &quot;-&quot;</span></li><li>  <span class="i">find_encoding</span><span class="s">(</span><span class="q">&quot;UTF8&quot;</span><span class="s">)</span><span class="i">-&gt;name</span>  <span class="c"># is &#39;utf8&#39;.</span></li></ol></pre><p>Perl's internal UTF8 flag is called "UTF8", without a hyphen. It indicates
whether a string is internally encoded as "utf8", also without a hyphen.</p>
<a name="SEE-ALSO"></a><h1>SEE ALSO</h1>
<p><a href="Encode/Encoding.html">Encode::Encoding</a>,
<a href="Encode/Supported.html">Encode::Supported</a>,
<a href="Encode/PerlIO.html">Encode::PerlIO</a>,
<a href="encoding.html">encoding</a>,
<a href="perlebcdic.html">perlebcdic</a>,
<a href="functions/open.html">open</a>,
<a href="perlunicode.html">perlunicode</a>, <a href="perluniintro.html">perluniintro</a>, <a href="perlunifaq.html">perlunifaq</a>, <a href="perlunitut.html">perlunitut</a>
<a href="utf8.html">utf8</a>,
the Perl Unicode Mailing List <a href="http://lists.perl.org/list/perl-unicode.html">http://lists.perl.org/list/perl-unicode.html</a></p>
<a name="MAINTAINER"></a><h1>MAINTAINER</h1>
<p>This project was originated by the late Nick Ing-Simmons and later
maintained by Dan Kogai <i>&lt;dankogai@cpan.org&gt;</i>.  See AUTHORS
for a full list of people involved.  For any questions, send mail to
<i>&lt;perl-unicode@perl.org&gt;</i> so that we can all share.</p>
<p>While Dan Kogai retains the copyright as a maintainer, credit
should go to all those involved.  See AUTHORS for a list of those
who submitted code to the project.</p>
<a name="COPYRIGHT"></a><h1>COPYRIGHT</h1>
<p>Copyright 2002-2014 Dan Kogai <i>&lt;dankogai@cpan.org&gt;</i>.</p>
<p>This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.</p>




  <div id="page_index" class="hud_container">
    <div id="page_index_header" class="hud_header">
      <div id="page_index_close" class="hud_close"><a href="#" onClick="pageIndex.hide();return false;"></a></div>
      <div id="page_index_title" class="hud_title"><span class="hud_span_top">Page index</span></div>
      <div id="page_index_topright" class="hud_topright"></div>
    </div>
    <div id="page_index_content" class="hud_content">
      <ul><li><a href="#NAME">NAME</a><li><a href="#SYNOPSIS">SYNOPSIS</a><ul><li><a href="#Table-of-Contents">Table of Contents</a></ul><li><a href="#DESCRIPTION">DESCRIPTION</a><ul><li><a href="#TERMINOLOGY">TERMINOLOGY</a></ul><li><a href="#THE-PERL-ENCODING-API">THE PERL ENCODING API</a><ul><li><a href="#Basic-methods">Basic methods</a><li><a href="#Listing-available-encodings">Listing available encodings</a><li><a href="#Defining-Aliases">Defining Aliases</a><li><a href="#Finding-IANA-Character-Set-Registry-names">Finding IANA Character Set Registry names</a></ul><li><a href="#Encoding-via-PerlIO">Encoding via PerlIO</a><li><a href="#Handling-Malformed-Data">Handling Malformed Data</a><ul><li><a href="#List-of-_CHECK_-values">List of _CHECK_ values</a><li><a href="#coderef-for-CHECK">coderef for CHECK</a></ul><li><a href="#Defining-Encodings">Defining Encodings</a><li><a href="#The-UTF8-flag">The UTF8 flag</a><ul><li><a href="#Messing-with-Perl's-Internals">Messing with Perl's Internals</a></ul><li><a href="#UTF-8-vs.-utf8-vs.-UTF8">UTF-8 vs. utf8 vs. UTF8</a><li><a href="#SEE-ALSO">SEE ALSO</a><li><a href="#MAINTAINER">MAINTAINER</a><li><a href="#COPYRIGHT">COPYRIGHT</a></ul>
    </div>
    <div id="page_index_footer" class="hud_footer">
      <div id="page_index_bottomleft" class="hud_bottomleft"></div>
      <div id="page_index_bottom" class="hud_bottom"><span class="hud_span_bottom"></span></div>
      <div id="page_index_resize" class="hud_resize"></div>
    </div>
  </div>


	    &nbsp;
          </div>
          <div id="content_footer">
          </div>
        </div>
        <div class="clear"></div>
      </div>
      
    <div id="footer">
      <div id="footer_content">
        <div id="footer_strapline">
          perldoc.perl.org - Official documentation for the Perl programming language
        </div>
        <div id="footer_links">
          <div id="address">
            <p class="name">Contact details</p>
            <p class="address">
	      Site maintained by <a href="mailto:jj@jonallen.info">Jon Allen (JJ)</a><br>
	    </p>
            <p class="contact">
              Documentation maintained by the <a href="http://lists.cpan.org/showlist.cgi?name=perl5-porters">Perl 5 Porters</a>
            </p>
          </div>
          <ul class="f1">
            <li>Manual
              <ul class="f2">
                <li><a href="index-overview.html">Overview</a>
                <li><a href="index-tutorials.html">Tutorials</a>
                <li><a href="index-faq.html">FAQs</a>
                <li><a href="index-history.html">Changes</a>
              </ul>
            <li>Reference
              <ul class="f2">
                <li><a href="index-language.html">Language</a>
                <li><a href="index-functions.html">Functions</a>
                <li><a href="perlop.html">Operators</a>
                <li><a href="perlvar.html">Variables</a>
              </ul>
            <li>Modules
              <ul class="f2">
                <li><a href="index-modules-A.html">Modules</a>
                <li><a href="index-pragmas.html">Pragmas</a>
                <li><a href="index-utilities.html">Utilities</a>
              </ul>
            <li>Misc
              <ul class="f2">
                <li><a href="index-licence.html">License</a>
                <li><a href="index-internals.html">Internals</a>
                <li><a href="index-platforms.html">Platforms</a>
              </ul>          </ul>
          <div class="clear"></div>
        </div>
      </div>
      <div id="footer_end">
      </div>
    </div>
      
    </div>
      <script language="JavaScript" type="text/javascript" src="static/exploreperl.js"></script>
      <script language="JavaScript" src="static/combined-20100403.js" type="text/javascript"></script>
<script language="JavaScript" type="text/javascript">
  perldoc.setPath(0);
  perldoc.pageName    = 'Encode';
  perldoc.pageAddress = 'Encode.html';
  perldoc.contentPage = 1;
  explorePerl.render();
  explorePerl.addEvents('explore_anchor');
</script>
    
  </body>
</html>