File: encoding.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 (796 lines) | stat: -rw-r--r-- 49,401 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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <title>encoding - 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>encoding</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-pragmas.html">Pragmas</a> &gt;
      
    
    encoding
  

            </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>encoding</h1>


  <!--    -->
<ul><li><a href="#NAME">NAME</a><li><a href="#WARNING">WARNING</a><li><a href="#SYNOPSIS">SYNOPSIS</a><li><a href="#DESCRIPTION">DESCRIPTION</a><li><a href="#OPTIONS">OPTIONS</a><ul><li><a href="#Setting-STDIN-and%2for-STDOUT-individually">Setting STDIN and/or STDOUT individually</a><li><a href="#The-%3alocale-sub-pragma">The :locale sub-pragma</a></ul><li><a href="#CAVEATS">CAVEATS</a><ul><li><a href="#SIDE-EFFECTS">SIDE EFFECTS</a><li><a href="#DO-NOT-MIX-MULTIPLE-ENCODINGS">DO NOT MIX MULTIPLE ENCODINGS</a><li><a href="#Prior-to-Perl-v5.22">Prior to Perl v5.22</a><li><a href="#Prior-to-Encode-version-1.87">Prior to Encode version 1.87</a><li><a href="#Prior-to-Perl-v5.8.1">Prior to Perl v5.8.1</a></ul><li><a href="#EXAMPLE---Greekperl">EXAMPLE - Greekperl</a><li><a href="#BUGS">BUGS</a><li><a href="#HISTORY">HISTORY</a><li><a href="#SEE-ALSO">SEE ALSO</a></ul><a name="NAME"></a><h1>NAME</h1>
<p>encoding - allows you to write your script in non-ASCII and non-UTF-8</p>
<a name="WARNING"></a><h1>WARNING</h1>
<p>This module has been deprecated since perl v5.18.  See <a href="#DESCRIPTION">DESCRIPTION</a> and
<a href="#BUGS">BUGS</a>.</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">encoding</span> <span class="q">&quot;greek&quot;</span><span class="sc">;</span>  <span class="c"># Perl like Greek to you?</span></li><li>  <a class="l_k" href="functions/use.html">use</a> <span class="w">encoding</span> <span class="q">&quot;euc-jp&quot;</span><span class="sc">;</span> <span class="c"># Jperl!</span></li><li></li><li>  <span class="c"># or you can even do this if your shell supports your native encoding</span></li><li></li><li>  <span class="w">perl</span> -<span class="w">Mencoding</span>=<span class="w">latin2</span> -e<span class="q">&#39;...&#39;</span> <span class="c"># Feeling centrally European?</span></li><li>  <span class="w">perl</span> -<span class="w">Mencoding</span>=<span class="w">euc</span>-<span class="w">kr</span> -e<span class="q">&#39;...&#39;</span> <span class="c"># Or Korean?</span></li><li></li><li>  <span class="c"># more control</span></li><li></li><li>  <span class="c"># A simple euc-cn =&gt; utf-8 converter</span></li><li>  <a class="l_k" href="functions/use.html">use</a> <span class="w">encoding</span> <span class="q">&quot;euc-cn&quot;</span><span class="cm">,</span> <span class="w">STDOUT</span> <span class="cm">=&gt;</span> <span class="q">&quot;utf8&quot;</span><span class="sc">;</span>  <a class="l_k" href="functions/while.html">while</a><span class="s">(</span>&lt;&gt;<span class="s">)</span><span class="s">{</span><a class="l_k" href="functions/print.html">print</a><span class="s">}</span><span class="sc">;</span></li><li></li><li>  <span class="c"># &quot;no encoding;&quot; supported</span></li><li>  <a class="l_k" href="functions/no.html">no</a> <span class="w">encoding</span><span class="sc">;</span></li><li></li><li>  <span class="c"># an alternate way, Filter</span></li><li>  <a class="l_k" href="functions/use.html">use</a> <span class="w">encoding</span> <span class="q">&quot;euc-jp&quot;</span><span class="cm">,</span> <span class="w">Filter</span><span class="cm">=&gt;</span><span class="n">1</span><span class="sc">;</span></li><li>  <span class="c"># now you can use kanji identifiers -- in euc-jp!</span></li><li></li><li>  <span class="c"># encode based on the current locale - specialized purposes only;</span></li><li>  <span class="c"># fraught with danger!!</span></li><li>  <a class="l_k" href="functions/use.html">use</a> <span class="w">encoding</span> <span class="q">&#39;:locale&#39;</span><span class="sc">;</span></li></ol></pre><a name="DESCRIPTION"></a><h1>DESCRIPTION</h1>
<p>This pragma is used to enable a Perl script to be written in encodings that
aren't strictly ASCII nor UTF-8.  It translates all or portions of the Perl
program script from a given encoding into UTF-8, and changes the PerlIO layers
of <code class="inline"><span class="w">STDIN</span></code>
 and <code class="inline"><span class="w">STDOUT</span></code>
 to the encoding specified.</p>
<p>This pragma dates from the days when UTF-8-enabled editors were uncommon.  But
that was long ago, and the need for it is greatly diminished.  That, coupled
with the fact that it doesn't work with threads, along with other problems,
(see <a href="#BUGS">BUGS</a>) have led to its being deprecated.  It is planned to remove this
pragma in a future Perl version.  New code should be written in UTF-8, and the
<code class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="w">utf8</span></code>
 pragma used instead (see <a href="perluniintro.html">perluniintro</a> and <a href="utf8.html">utf8</a> for details).
Old code should be converted to UTF-8, via something like the recipe in the
<a href="#SYNOPSIS">SYNOPSIS</a> (though this simple approach may require manual adjustments
afterwards).</p>
<p>If UTF-8 is not an option, it is recommended that one use a simple source
filter, such as that provided by <a href="http://search.cpan.org/perldoc/Filter::Encoding">Filter::Encoding</a> on CPAN or this
pragma's own <code class="inline"><span class="w">Filter</span></code>
 option (see below).</p>
<p>The only legitimate use of this pragma is almost certainly just one per file,
near the top, with file scope, as the file is likely going to only be written
in one encoding.  Further restrictions apply in Perls before v5.22 (see
<a href="#Prior-to-Perl-v5.22">Prior to Perl v5.22</a>).</p>
<p>There are two basic modes of operation (plus turning if off):</p>
<ul>
<li><a name="use-encoding-%5b'_ENCNAME_'%5d-%3b"></a><b><code class="inline">use encoding ['<i>ENCNAME</i>'] ;</code></b>
<p>Please note: This mode of operation is no longer supported as of Perl
v5.26.</p>
<p>This is the normal operation.  It translates various literals encountered in
the Perl source file from the encoding <i>ENCNAME</i> into UTF-8, and similarly
converts character code points.  This is used when the script is a combination
of ASCII (for the variable names and punctuation, <i>etc</i>), but the literal
data is in the specified encoding.</p>
<p><i>ENCNAME</i> is optional.  If omitted, the encoding specified in the environment
variable <a href="perlrun.html#PERL_ENCODING">PERL_ENCODING </a> is used.  If this isn't
set, or the resolved-to encoding is not known to <code class="inline"><a href="Encode.html">Encode</a></code>, the error
<code class="inline">Unknown encoding '<i>ENCNAME</i>'</code> will be thrown.</p>
<p>Starting in Perl v5.8.6 (<code class="inline"><span class="w">Encode</span></code>
 version 2.0.1), <i>ENCNAME</i> may be the
name <code class="inline"><span class="j">:</span><span class="w">locale</span></code>
.  This is for very specialized applications, and is documented
in <a href="#The-%3alocale-sub-pragma">The :locale sub-pragma</a> below.</p>
<p>The literals that are converted are <code class="inline"><span class="q">q//</span><span class="cm">,</span> <span class="q">qq//</span><span class="cm">,</span> <span class="q">qr//</span><span class="cm">,</span> <span class="q">qw//</span>/<span class="cm">,</span> <span class="q">qx//</span></code>
, and
starting in v5.8.1, <code class="inline"><a class="l_k" href="functions/tr.html">tr///</a></code>.  Operations that do conversions include <code class="inline"><a class="l_k" href="functions/chr.html">chr</a></code>,
<code class="inline"><a class="l_k" href="functions/ord.html">ord</a></code>, <code class="inline"><span class="w">utf8::upgrade</span></code>
 (but not <code class="inline"><span class="w">utf8::downgrade</span></code>
), and <code class="inline"><a class="l_k" href="functions/chomp.html">chomp</a></code>.</p>
<p>Also starting in v5.8.1, the <code class="inline"><span class="w">DATA</span></code>
 pseudo-filehandle is translated from the
encoding into UTF-8.</p>
<p>For example, you can write code in EUC-JP as follows:</p>
<pre class="verbatim"><ol><li>  <a class="l_k" href="functions/my.html">my</a> <span class="i">$Rakuda</span> = <span class="q">&quot;\xF1\xD1\xF1\xCC&quot;</span><span class="sc">;</span> <span class="c"># Camel in Kanji</span></li><li>               <span class="c">#&lt;-char-&gt;&lt;-char-&gt;   # 4 octets</span></li><li>  <span class="q">s/\bCamel\b/$Rakuda/</span><span class="sc">;</span></li></ol></pre><p>And with <code class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="w">encoding</span> <span class="q">&quot;euc-jp&quot;</span></code>
 in effect, it is the same thing as
that code in UTF-8:</p>
<pre class="verbatim"><ol><li>  <a class="l_k" href="functions/my.html">my</a> <span class="i">$Rakuda</span> = <span class="q">&quot;\x{99F1}\x{99DD}&quot;</span><span class="sc">;</span> <span class="c"># two Unicode Characters</span></li><li>  <span class="q">s/\bCamel\b/$Rakuda/</span><span class="sc">;</span></li></ol></pre><p>See <a href="#EXAMPLE">EXAMPLE</a> below for a more complete example.</p>
<p>Unless <code class="inline"><span class="i">$</span>{<span class="w">^UNICODE</span>}</code>
 (available starting in v5.8.2) exists and is non-zero, the
PerlIO layers of <code class="inline"><span class="w">STDIN</span></code>
 and <code class="inline"><span class="w">STDOUT</span></code>
 are set to "<code class="inline">:encoding(<i>ENCNAME</i>)</code>".
Therefore,</p>
<pre class="verbatim"><ol><li>  <a class="l_k" href="functions/use.html">use</a> <span class="w">encoding</span> <span class="q">&quot;euc-jp&quot;</span><span class="sc">;</span></li><li>  <a class="l_k" href="functions/my.html">my</a> <span class="i">$message</span> = <span class="q">&quot;Camel is the symbol of perl.\n&quot;</span><span class="sc">;</span></li><li>  <a class="l_k" href="functions/my.html">my</a> <span class="i">$Rakuda</span> = <span class="q">&quot;\xF1\xD1\xF1\xCC&quot;</span><span class="sc">;</span> <span class="c"># Camel in Kanji</span></li><li>  <span class="i">$message</span> =~ <span class="q">s/\bCamel\b/$Rakuda/</span><span class="sc">;</span></li><li>  <a class="l_k" href="functions/print.html">print</a> <span class="i">$message</span><span class="sc">;</span></li></ol></pre><p>will print</p>
<pre class="verbatim"><ol><li> <span class="q">&quot;\xF1\xD1\xF1\xCC is the symbol of perl.\n&quot;</span></li></ol></pre><p>not</p>
<pre class="verbatim"><ol><li> <span class="q">&quot;\x{99F1}\x{99DD} is the symbol of perl.\n&quot;</span></li></ol></pre><p>You can override this by giving extra arguments; see below.</p>
<p>Note that <code class="inline"><span class="w">STDERR</span></code>
 WILL NOT be changed, regardless.</p>
<p>Also note that non-STD file handles remain unaffected.  Use <code class="inline"><a class="l_k" href="functions/use.html">use</a>
<a class="l_k" href="functions/open.html">open</a></code>
 or <code class="inline"><a class="l_k" href="functions/binmode.html">binmode</a></code> to change the layers of those.</p>
</li>
<li><a name="use-encoding-_ENCNAME_-Filter%3d%3e1%3b"></a><b><code class="inline">use encoding <i>ENCNAME</i> Filter=&gt;1;</code></b>
<p>This operates as above, but the <code class="inline"><span class="w">Filter</span></code>
 argument with a non-zero
value causes the entire script, and not just literals, to be translated from
the encoding into UTF-8.  This allows identifiers in the source to be in that
encoding as well.  (Problems may occur if the encoding is not a superset of
ASCII; imagine all your semi-colons being translated into something
different.)  One can use this form to make</p>
<pre class="verbatim"><ol><li> <span class="i">$</span>{<span class="q">&quot;\x{4eba}&quot;</span>}++</li></ol></pre><p>work.  (This is equivalent to <code class="inline">$<i>human</i>++</code>, where <i>human</i> is a single Han
ideograph).</p>
<p>This effectively means that your source code behaves as if it were written in
UTF-8 with <code class="inline"><span class="q">&#39;use utf8</span></code>
' in effect.  So even if your editor only supports
Shift_JIS, for example, you can still try examples in Chapter 15 of
<code class="inline">Programming Perl, 3rd Ed.</code>.</p>
<p>This option is significantly slower than the other one.</p>
</li>
<li><a name="no-encoding%3b"></a><b><code class="inline"><a class="l_k" href="functions/no.html">no</a> <span class="w">encoding</span><span class="sc">;</span></code>
</b>
<p>Unsets the script encoding. The layers of <code class="inline"><span class="w">STDIN</span></code>
, <code class="inline"><span class="w">STDOUT</span></code>
 are
reset to "<code class="inline"><span class="j">:</span><span class="w">raw</span></code>
" (the default unprocessed raw stream of bytes).</p>
</li>
</ul>
<a name="OPTIONS"></a><h1>OPTIONS</h1>
<a name="Setting-STDIN-and%2for-STDOUT-individually"></a><h2>Setting <code class="inline"><span class="w">STDIN</span></code>
 and/or <code class="inline"><span class="w">STDOUT</span></code>
 individually</h2>
<p>The encodings of <code class="inline"><span class="w">STDIN</span></code>
 and <code class="inline"><span class="w">STDOUT</span></code>
 are individually settable by parameters to
the pragma:</p>
<pre class="verbatim"><ol><li> <a class="l_k" href="functions/use.html">use</a> <span class="w">encoding</span> <span class="q">&#39;euc-tw&#39;</span><span class="cm">,</span> <span class="w">STDIN</span> <span class="cm">=&gt;</span> <span class="q">&#39;greek&#39;</span>  ...<span class="sc">;</span></li></ol></pre><p>In this case, you cannot omit the first <i>ENCNAME</i>.  <code class="inline"><span class="w">STDIN</span> <span class="cm">=&gt;</span> <a class="l_k" href="functions/undef.html">undef</a></code>

turns the I/O transcoding completely off for that filehandle.</p>
<p>When <code class="inline"><span class="i">$</span>{<span class="w">^UNICODE</span>}</code>
 (available starting in v5.8.2) exists and is non-zero,
these options will be completely ignored.  See <a href="perlvar.html#%24%7b%5eUNICODE%7d">${^UNICODE} in perlvar</a> and
<a href="perlrun.html#-C-%5bnumber%2flist%5d">-C  in perlrun</a> for details.</p>
<a name="The-%3alocale-sub-pragma"></a><h2>The <code class="inline"><span class="j">:</span><span class="w">locale</span></code>
 sub-pragma</h2>
<p>Starting in v5.8.6, the encoding name may be <code class="inline"><span class="j">:</span><span class="w">locale</span></code>
.  This means that the
encoding is taken from the current locale, and not hard-coded by the pragma.
Since a script really can only be encoded in exactly one encoding, this option
is dangerous.  It makes sense only if the script itself is written in ASCII,
and all the possible locales that will be in use when the script is executed
are supersets of ASCII.  That means that the script itself doesn't get
changed, but the I/O handles have the specified encoding added, and the
operations like <code class="inline"><a class="l_k" href="functions/chr.html">chr</a></code> and <code class="inline"><a class="l_k" href="functions/ord.html">ord</a></code> use that encoding.</p>
<p>The logic of finding which locale <code class="inline"><span class="j">:</span><span class="w">locale</span></code>
 uses is as follows:</p>
<dl>
<dt>1.</dt><dd>
<p>If the platform supports the <code class="inline"><span class="i">langinfo</span><span class="s">(</span><span class="w">CODESET</span><span class="s">)</span></code>
 interface, the codeset
returned is used as the default encoding for the open pragma.</p>
</dd>
<dt>2.</dt><dd>
<p>If 1. didn't work but we are under the locale pragma, the environment
variables <code class="inline"><span class="w">LC_ALL</span></code>
 and <code class="inline"><span class="w">LANG</span></code>
 (in that order) are matched for encodings
(the part after "<code class="inline">.</code>", if any), and if any found, that is used
as the default encoding for the open pragma.</p>
</dd>
<dt>3.</dt><dd>
<p>If 1. and 2. didn't work, the environment variables <code class="inline"><span class="w">LC_ALL</span></code>
 and <code class="inline"><span class="w">LANG</span></code>

(in that order) are matched for anything looking like UTF-8, and if
any found, <code class="inline"><span class="j">:</span><span class="w">utf8</span></code>
 is used as the default encoding for the open
pragma.</p>
</dd>
</dl>
<p>If your locale environment variables (<code class="inline"><span class="w">LC_ALL</span></code>
, <code class="inline"><span class="w">LC_CTYPE</span></code>
, <code class="inline"><span class="w">LANG</span></code>
)
contain the strings 'UTF-8' or 'UTF8' (case-insensitive matching),
the default encoding of your <code class="inline"><span class="w">STDIN</span></code>
, <code class="inline"><span class="w">STDOUT</span></code>
, and <code class="inline"><span class="w">STDERR</span></code>
, and of
<b>any subsequent file open</b>, is UTF-8.</p>
<a name="CAVEATS"></a><h1>CAVEATS</h1>
<a name="SIDE-EFFECTS"></a><h2>SIDE EFFECTS</h2>
<ul>
<li>
<p>If the <code class="inline"><span class="w">encoding</span></code>
 pragma is in scope then the lengths returned are
calculated from the length of <code class="inline"><span class="i">$/</span></code>
 in Unicode characters, which is not
always the same as the length of <code class="inline"><span class="i">$/</span></code>
 in the native encoding.</p>
</li>
<li>
<p>Without this pragma, if strings operating under byte semantics and strings
with Unicode character data are concatenated, the new string will
be created by decoding the byte strings as <i>ISO 8859-1 (Latin-1)</i>.</p>
<p>The <b>encoding</b> pragma changes this to use the specified encoding
instead.  For example:</p>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/use.html">use</a> <span class="w">encoding</span> <span class="q">&#39;utf8&#39;</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/my.html">my</a> <span class="i">$string</span> = <a class="l_k" href="functions/chr.html">chr</a><span class="s">(</span><span class="n">20000</span><span class="s">)</span><span class="sc">;</span> <span class="c"># a Unicode string</span></li><li>    <span class="i">utf8::encode</span><span class="s">(</span><span class="i">$string</span><span class="s">)</span><span class="sc">;</span>   <span class="c"># now it&#39;s a UTF-8 encoded byte string</span></li><li>    <span class="c"># concatenate with another Unicode string</span></li><li>    <a class="l_k" href="functions/print.html">print</a> <a class="l_k" href="functions/length.html">length</a><span class="s">(</span><span class="i">$string</span> . <a class="l_k" href="functions/chr.html">chr</a><span class="s">(</span><span class="n">20000</span><span class="s">)</span><span class="s">)</span><span class="sc">;</span></li></ol></pre><p>Will print <code class="inline"><span class="n">2</span></code>
, because <code class="inline"><span class="i">$string</span></code>
 is upgraded as UTF-8.  Without
<code class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="w">encoding</span> <span class="q">&#39;utf8&#39;</span><span class="sc">;</span></code>
, it will print <code class="inline"><span class="n">4</span></code>
 instead, since <code class="inline"><span class="i">$string</span></code>

is three octets when interpreted as Latin-1.</p>
</li>
</ul>
<a name="DO-NOT-MIX-MULTIPLE-ENCODINGS"></a><h2>DO NOT MIX MULTIPLE ENCODINGS</h2>
<p>Notice that only literals (string or regular expression) having only
legacy code points are affected: if you mix data like this</p>
<pre class="verbatim"><ol><li>    \<span class="i">x</span><span class="s">{</span><span class="n">100</span><span class="s">}</span>\<span class="w">xDF</span></li><li>    \<span class="w">xDF</span>\<span class="i">x</span><span class="s">{</span><span class="n">100</span><span class="s">}</span></li></ol></pre><p>the data is assumed to be in (Latin 1 and) Unicode, not in your native
encoding.  In other words, this will match in "greek":</p>
<pre class="verbatim"><ol><li>    <span class="q">&quot;\xDF&quot;</span> =~ <span class="q">/\x{3af}/</span></li></ol></pre><p>but this will not</p>
<pre class="verbatim"><ol><li>    <span class="q">&quot;\xDF\x{100}&quot;</span> =~ <span class="q">/\x{3af}\x{100}/</span></li></ol></pre><p>since the <code class="inline">\<span class="w">xDF</span></code>
 (ISO 8859-7 GREEK SMALL LETTER IOTA WITH TONOS) on
the left will <b>not</b> be upgraded to <code class="inline">\x{3af}</code> (Unicode GREEK SMALL
LETTER IOTA WITH TONOS) because of the <code class="inline">\<span class="i">x</span><span class="s">{</span><span class="n">100</span><span class="s">}</span></code>
 on the left.  You
should not be mixing your legacy data and Unicode in the same string.</p>
<p>This pragma also affects encoding of the 0x80..0xFF code point range:
normally characters in that range are left as eight-bit bytes (unless
they are combined with characters with code points 0x100 or larger,
in which case all characters need to become UTF-8 encoded), but if
the <code class="inline"><span class="w">encoding</span></code>
 pragma is present, even the 0x80..0xFF range always
gets UTF-8 encoded.</p>
<p>After all, the best thing about this pragma is that you don't have to
resort to \x{....} just to spell your name in a native encoding.
So feel free to put your strings in your encoding in quotes and
regexes.</p>
<a name="Prior-to-Perl-v5.22"></a><h2>Prior to Perl v5.22</h2>
<p>The pragma was a per script, not a per block lexical.  Only the last
<code class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="w">encoding</span></code>
 or <code class="inline"><a class="l_k" href="functions/no.html">no</a> <span class="w">encoding</span></code>
 mattered, and it affected
<b>the whole script</b>.  However, the <code class="inline"><a class="l_k" href="functions/no.html">no</a> <span class="w">encoding</span></code>
 pragma was supported and
<code class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="w">encoding</span></code>
 could appear as many times as you want in a given script
(though only the last was effective).</p>
<p>Since the scope wasn't lexical, other modules' use of <code class="inline"><a class="l_k" href="functions/chr.html">chr</a></code>, <code class="inline"><a class="l_k" href="functions/ord.html">ord</a></code>, <i>etc.</i>
were affected.  This leads to spooky, incorrect action at a distance that is
hard to debug.</p>
<p>This means you would have to be very careful of the load order:</p>
<pre class="verbatim"><ol><li>  # called module</li><li>  package Module_IN_BAR;</li><li>  use encoding "bar";</li><li>  # stuff in "bar" encoding here</li><li>  1;</li><li></li><li>  # caller script</li><li>  use encoding "foo"</li><li>  use Module_IN_BAR;</li><li>  # surprise! use encoding "bar" is in effect.</li></ol></pre><p>The best way to avoid this oddity is to use this pragma RIGHT AFTER
other modules are loaded.  i.e.</p>
<pre class="verbatim"><ol><li>  <a class="l_k" href="functions/use.html">use</a> <span class="w">Module_IN_BAR</span><span class="sc">;</span></li><li>  <a class="l_k" href="functions/use.html">use</a> <span class="w">encoding</span> <span class="q">&quot;foo&quot;</span><span class="sc">;</span></li></ol></pre><a name="Prior-to-Encode-version-1.87"></a><h2>Prior to Encode version 1.87</h2>
<ul>
<li>
<p><code class="inline"><span class="w">STDIN</span></code>
 and <code class="inline"><span class="w">STDOUT</span></code>
 were not set under the filter option.
And <code class="inline">STDIN=&gt;<i>ENCODING</i></code> and <code class="inline">STDOUT=&gt;<i>ENCODING</i></code> didn't work like
non-filter version.</p>
</li>
<li>
<p><code class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="w">utf8</span></code>
 wasn't implicitly declared so you have to <code class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="w">utf8</span></code>
 to do</p>
<pre class="verbatim"><ol><li> <span class="i">$</span>{<span class="q">&quot;\x{4eba}&quot;</span>}++</li></ol></pre></li>
</ul>
<a name="Prior-to-Perl-v5.8.1"></a><h2>Prior to Perl v5.8.1</h2>
<ul>
<li><a name="%22NON-EUC%22-doublebyte-encodings"></a><b>"NON-EUC" doublebyte encodings</b>
<p>Because perl needs to parse the script before applying this pragma, such
encodings as Shift_JIS and Big-5 that may contain <code class="inline">'\'</code> (BACKSLASH;
<code class="inline">\<span class="w">x5c</span></code>
) in the second byte fail because the second byte may
accidentally escape the quoting character that follows.</p>
</li>
<li><a name="tr%2f%2f%2f"></a><b><code class="inline"><a class="l_k" href="functions/tr.html">tr///</a></code></b>
<p>The <b>encoding</b> pragma works by decoding string literals in
<code class="inline"><span class="q">q//</span><span class="cm">,</span><span class="q">qq//</span><span class="cm">,</span><span class="q">qr//</span><span class="cm">,</span><span class="q">qw//</span>/<span class="cm">,</span> <span class="q">qx//</span></code>
 and so forth.  In perl v5.8.0, this
does not apply to <code class="inline"><a class="l_k" href="functions/tr.html">tr///</a></code>.  Therefore,</p>
<pre class="verbatim"><ol><li>  <a class="l_k" href="functions/use.html">use</a> <span class="w">encoding</span> <span class="q">&#39;euc-jp&#39;</span><span class="sc">;</span></li><li>  <span class="c">#....</span></li><li>  <span class="i">$kana</span> =~ <span class="q">tr/\xA4\xA1-\xA4\xF3/\xA5\xA1-\xA5\xF3/</span><span class="sc">;</span></li><li>  <span class="c">#           -------- -------- -------- --------</span></li></ol></pre><p>Does not work as</p>
<pre class="verbatim"><ol><li>  <span class="i">$kana</span> =~ <span class="q">tr/\x{3041}-\x{3093}/\x{30a1}-\x{30f3}/</span><span class="sc">;</span></li></ol></pre><ul>
<li><a name="Legend-of-characters-above"></a><b>Legend of characters above</b>
<pre class="verbatim"><ol><li>  utf8     euc-jp   charnames::viacode()</li><li>  -----------------------------------------</li><li>  \x{3041} \xA4\xA1 HIRAGANA LETTER SMALL A</li><li>  \x{3093} \xA4\xF3 HIRAGANA LETTER N</li><li>  \x{30a1} \xA5\xA1 KATAKANA LETTER SMALL A</li><li>  \x{30f3} \xA5\xF3 KATAKANA LETTER N</li></ol></pre></li>
</ul>
<p>This counterintuitive behavior has been fixed in perl v5.8.1.</p>
<p>In perl v5.8.0, you can work around this as follows;</p>
<pre class="verbatim"><ol><li>  <a class="l_k" href="functions/use.html">use</a> <span class="w">encoding</span> <span class="q">&#39;euc-jp&#39;</span><span class="sc">;</span></li><li>  <span class="c">#  ....</span></li><li>  <a class="l_k" href="functions/eval.html">eval</a> <span class="q">qq{ \$kana =~ tr/\xA4\xA1-\xA4\xF3/\xA5\xA1-\xA5\xF3/ }</span><span class="sc">;</span></li></ol></pre><p>Note the <code class="inline"><a class="l_k" href="functions/tr.html">tr//</a></code> expression is surrounded by <code class="inline"><a class="l_k" href="functions/qq.html">qq{}</a></code>.  The idea behind
this is the same as the classic idiom that makes <code class="inline"><a class="l_k" href="functions/tr.html">tr///</a></code> 'interpolate':</p>
<pre class="verbatim"><ol><li>   <span class="q">tr/$from/$to/</span><span class="sc">;</span>            <span class="c"># wrong!</span></li><li>   <a class="l_k" href="functions/eval.html">eval</a> <span class="q">qq{ tr/$from/$to/ }</span><span class="sc">;</span> <span class="c"># workaround.</span></li></ol></pre></li>
</ul>
<a name="EXAMPLE---Greekperl"></a><h1>EXAMPLE - Greekperl</h1>
<pre class="verbatim"><ol><li>    <a class="l_k" href="functions/use.html">use</a> <span class="w">encoding</span> <span class="q">&quot;iso 8859-7&quot;</span><span class="sc">;</span></li><li></li><li>    <span class="c"># \xDF in ISO 8859-7 (Greek) is \x{3af} in Unicode.</span></li><li></li><li>    <span class="i">$a</span> = <span class="q">&quot;\xDF&quot;</span><span class="sc">;</span></li><li>    <span class="i">$b</span> = <span class="q">&quot;\x{100}&quot;</span><span class="sc">;</span></li><li></li><li>    <a class="l_k" href="functions/printf.html">printf</a> <span class="q">&quot;%#x\n&quot;</span><span class="cm">,</span> <a class="l_k" href="functions/ord.html">ord</a><span class="s">(</span><span class="i">$a</span><span class="s">)</span><span class="sc">;</span> <span class="c"># will print 0x3af, not 0xdf</span></li><li></li><li>    <span class="i">$c</span> = <span class="i">$a</span> . <span class="i">$b</span><span class="sc">;</span></li><li></li><li>    <span class="c"># $c will be &quot;\x{3af}\x{100}&quot;, not &quot;\x{df}\x{100}&quot;.</span></li><li></li><li>    <span class="c"># chr() is affected, and ...</span></li><li></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;mega\n&quot;</span>  if <a class="l_k" href="functions/ord.html">ord</a><span class="s">(</span><a class="l_k" href="functions/chr.html">chr</a><span class="s">(</span><span class="n">0xdf</span><span class="s">)</span><span class="s">)</span> == <span class="n">0x3af</span><span class="sc">;</span></li><li></li><li>    <span class="c"># ... ord() is affected by the encoding pragma ...</span></li><li></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;tera\n&quot;</span> if <a class="l_k" href="functions/ord.html">ord</a><span class="s">(</span><a class="l_k" href="functions/pack.html">pack</a><span class="s">(</span><span class="q">&quot;C&quot;</span><span class="cm">,</span> <span class="n">0xdf</span><span class="s">)</span><span class="s">)</span> == <span class="n">0x3af</span><span class="sc">;</span></li><li></li><li>    <span class="c"># ... as are eq and cmp ...</span></li><li></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;peta\n&quot;</span> if <span class="q">&quot;\x{3af}&quot;</span> eq  <a class="l_k" href="functions/pack.html">pack</a><span class="s">(</span><span class="q">&quot;C&quot;</span><span class="cm">,</span> <span class="n">0xdf</span><span class="s">)</span><span class="sc">;</span></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;exa\n&quot;</span>  if <span class="q">&quot;\x{3af}&quot;</span> cmp <a class="l_k" href="functions/pack.html">pack</a><span class="s">(</span><span class="q">&quot;C&quot;</span><span class="cm">,</span> <span class="n">0xdf</span><span class="s">)</span> == <span class="n">0</span><span class="sc">;</span></li><li></li><li>    <span class="c"># ... but pack/unpack C are not affected, in case you still</span></li><li>    <span class="c"># want to go back to your native encoding</span></li><li></li><li>    <a class="l_k" href="functions/print.html">print</a> <span class="q">&quot;zetta\n&quot;</span> if <a class="l_k" href="functions/unpack.html">unpack</a><span class="s">(</span><span class="q">&quot;C&quot;</span><span class="cm">,</span> <span class="s">(</span><a class="l_k" href="functions/pack.html">pack</a><span class="s">(</span><span class="q">&quot;C&quot;</span><span class="cm">,</span> <span class="n">0xdf</span><span class="s">)</span><span class="s">)</span><span class="s">)</span> == <span class="n">0xdf</span><span class="sc">;</span></li></ol></pre><a name="BUGS"></a><h1>BUGS</h1>
<ul>
<li><a name="Thread-safety"></a><b>Thread safety</b>
<p><code class="inline"><a class="l_k" href="functions/use.html">use</a> <span class="w">encoding</span> ...</code>
 is not thread-safe (i.e., do not use in threaded
applications).</p>
</li>
<li><a name="Can't-be-used-by-more-than-one-module-in-a-single-program."></a><b>Can't be used by more than one module in a single program.</b>
<p>Only one encoding is allowed.  If you combine modules in a program that have
different encodings, only one will be actually used.</p>
</li>
<li><a name="Other-modules-using-STDIN-and-STDOUT-get-the-encoded-stream"></a><b>Other modules using <code class="inline"><span class="w">STDIN</span></code>
 and <code class="inline"><span class="w">STDOUT</span></code>
 get the encoded stream</b>
<p>They may be expecting something completely different.</p>
</li>
<li><a name="literals-in-regex-that-are-longer-than-127-bytes"></a><b>literals in regex that are longer than 127 bytes</b>
<p>For native multibyte encodings (either fixed or variable length),
the current implementation of the regular expressions may introduce
recoding errors for regular expression literals longer than 127 bytes.</p>
</li>
<li><a name="EBCDIC"></a><b>EBCDIC</b>
<p>The encoding pragma is not supported on EBCDIC platforms.</p>
</li>
<li><a name="format"></a><b><code class="inline"><a class="l_k" href="functions/format.html">format</a></code></b>
<p>This pragma doesn't work well with <code class="inline"><a class="l_k" href="functions/format.html">format</a></code> because PerlIO does not
get along very well with it.  When <code class="inline"><a class="l_k" href="functions/format.html">format</a></code> contains non-ASCII
characters it prints funny or gets "wide character warnings".
To understand it, try the code below.</p>
<pre class="verbatim"><ol><li>  # Save this one in utf8</li><li>  # replace *non-ascii* with a non-ascii string</li><li>  my $camel;</li><li>  format STDOUT =</li><li>  *non-ascii*@&gt;&gt;&gt;&gt;&gt;&gt;&gt;</li><li>  $camel</li><li>  .</li><li>  $camel = "*non-ascii*";</li><li>  binmode(STDOUT=&gt;':encoding(utf8)'); # bang!</li><li>  write;              # funny</li><li>  print $camel, "\n"; # fine</li></ol></pre><p>Without binmode this happens to work but without binmode, print()
fails instead of write().</p>
<p>At any rate, the very use of <code class="inline"><a class="l_k" href="functions/format.html">format</a></code> is questionable when it comes to
unicode characters since you have to consider such things as character
width (i.e. double-width for ideographs) and directions (i.e. BIDI for
Arabic and Hebrew).</p>
</li>
<li><a name="See-also-the-%2fCAVEATS-manpage"></a><b>See also <a href="#CAVEATS">CAVEATS</a></b>
</li>
</ul>
<a name="HISTORY"></a><h1>HISTORY</h1>
<p>This pragma first appeared in Perl v5.8.0.  It has been enhanced in later
releases as specified above.</p>
<a name="SEE-ALSO"></a><h1>SEE ALSO</h1>
<p><a href="perlunicode.html">perlunicode</a>, <a href="Encode.html">Encode</a>, <a href="open.html">open</a>, <a href="Filter/Util/Call.html">Filter::Util::Call</a>,</p>
<p>Ch. 15 of <code class="inline">Programming Perl (3rd Edition)</code>
by Larry Wall, Tom Christiansen, Jon Orwant;
O'Reilly &amp; Associates; ISBN 0-596-00027-8</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="#WARNING">WARNING</a><li><a href="#SYNOPSIS">SYNOPSIS</a><li><a href="#DESCRIPTION">DESCRIPTION</a><li><a href="#OPTIONS">OPTIONS</a><ul><li><a href="#Setting-STDIN-and%2for-STDOUT-individually">Setting STDIN and/or STDOUT individually</a><li><a href="#The-%3alocale-sub-pragma">The :locale sub-pragma</a></ul><li><a href="#CAVEATS">CAVEATS</a><ul><li><a href="#SIDE-EFFECTS">SIDE EFFECTS</a><li><a href="#DO-NOT-MIX-MULTIPLE-ENCODINGS">DO NOT MIX MULTIPLE ENCODINGS</a><li><a href="#Prior-to-Perl-v5.22">Prior to Perl v5.22</a><li><a href="#Prior-to-Encode-version-1.87">Prior to Encode version 1.87</a><li><a href="#Prior-to-Perl-v5.8.1">Prior to Perl v5.8.1</a></ul><li><a href="#EXAMPLE---Greekperl">EXAMPLE - Greekperl</a><li><a href="#BUGS">BUGS</a><li><a href="#HISTORY">HISTORY</a><li><a href="#SEE-ALSO">SEE ALSO</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    = 'encoding';
  perldoc.pageAddress = 'encoding.html';
  perldoc.contentPage = 1;
  explorePerl.render();
  explorePerl.addEvents('explore_anchor');
</script>
    
  </body>
</html>