File: PerlIO.html

package info (click to toggle)
perl-doc-html 5.10.0-2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 23,252 kB
  • ctags: 22,194
  • sloc: makefile: 6
file content (380 lines) | stat: -rw-r--r-- 25,559 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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
  <title>PerlIO - 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 href="css.css" rel="stylesheet" rev="stylesheet" type="text/css" media="screen" />
</head>

<script language="JavaScript" type="text/javascript" src="label.js"></script>

<script language="JavaScript">
  pageDepth = 0;
  setPath();
</script>

<body onLoad="showToolbars();loadLabels()">

<div id="pageHeader">
  <div id="pageHeaderLogo">
    <img src="onion.gif">
  </div>
  <div id="pageHeaderText">
    <a href="http://perldoc.perl.org">perldoc.perl.org</a>
  </div>
</div>

<div id="pageBody">
  <div id="left">
    <div id="leftContent">
      <div id="leftClose">
        <a href="#" onClick="closeLeft()" title="Hide navigation" onmouseover="leftCloseIcon.src='close_purple.gif';" onmouseout="leftCloseIcon.src='close_blue.gif';"><img src="close_blue.gif" name="leftCloseIcon" id="leftCloseIcon" border=0></a>
      </div>
      <h1>Manual:</h1>
      <ul>
        <li><a href="index-overview.html">Overview</a></li>
        <li><a href="index-tutorials.html">Tutorials</a></li>
        <li><a href="index-faq.html">FAQs</a></li>
        <li><a href="index-history.html">History / Changes</a></li>
        <li><a href="index-licence.html">Licence</a></li>
      </ul>
      <h2>Reference:</h2>
      <ul>
        <li><a href="index-language.html">Language</a></li>
        <li><a href="index-functions.html">Functions</a></li>
        <li><a href="perlop.html">Operators</a></li>
        <li><a href="perlvar.html">Special variables</a></li>
        <li><a href="index-pragmas.html">Pragmas</a></li>
        <li><a href="index-modules-A.html">Core modules</a></li>
        <li><a href="index-utilities.html">Utilities</a></li>
        <li><a href="index-internals.html">Internals</a></li>
        <li><a href="index-platforms.html">Platform specific</a></li>
      </ul>
      <h2>Links:</h2>
      <ul>
        <li><a href="http://search.cpan.org">CPAN</a></li>
        <li><a href="http://www.perl.org">Perl.org</a></li>
        <li><a href="http://www.perl.com">Perl.com</a></li>
        <li><a href="http://perlbuzz.com">Perl Buzz</a></li>
        <li><a href="http://www.perlfoundation.org/perl5/index.cgi">Perl 5 Wiki</a></li>
        <li><a href="http://jobs.perl.org">Perl Jobs</a></li>
        <li><a href="http://www.pm.org">Perl Mongers</a></li>
        <li><a href="http://www.perlmonks.org">Perl Monks</a></li>
        <li><a href="http://planet.perl.org">Planet Perl</a></li>
        <li><a href="http://use.perl.org">Use Perl</a></li>
      </ul>
      <h2>Contact:</h2>
      <ul>
        <li>Site maintained by<br><a href="http://perl.jonallen.info">Jon Allen</a>
            (<a href="http://perl.jonallen.info">JJ</a>)</li>
        <li class="spaced">Last updated on<br>23 December 2007</li>
	<li class="spaced">See the <a href="http://perl.jonallen.info/projects/perldoc">project page</a> for
	more details</li>
      </ul>
    </div>
  </div>

  <div id="center">  
    <div id="centerContent">
      <div id="contentHeader">
        <div id="contentHeaderLeft"><a href="#" onClick="showLeft()">Show navigation</a></div>
        <div id="contentHeaderCentre">-- Perl 5.10.0 documentation --</div>
        <div id="contentHeaderRight"><a href="#" onClick="showRight()">Show toolbar</a></div>
      </div>
      <div id="breadCrumbs"><a href="index.html">Home</a> &gt; <a href="index-modules-A.html">Core modules</a> &gt; <a href="index-modules-P.html">P</a> &gt; PerlIO</div>
      <script language="JavaScript">fromSearch();</script>
      <div id="contentBody"><div class="title_container"><div class="page_title">PerlIO</div></div><ul><li><a href="#NAME">NAME</a><li><a href="#SYNOPSIS">SYNOPSIS</a><li><a href="#DESCRIPTION">DESCRIPTION</a><ul><li><a href="#Custom-Layers">Custom Layers</a><li><a href="#Alternatives-to-raw">Alternatives to raw</a><li><a href="#Defaults-and-how-to-override-them">Defaults and how to override them</a><li><a href="#Querying-the-layers-of-filehandles">Querying the layers of filehandles</a></ul><li><a href="#AUTHOR">AUTHOR</a><li><a href="#SEE-ALSO">SEE ALSO</a></ul><a name="NAME"></a><h1>NAME</h1>
<p>PerlIO - On demand loader for PerlIO layers and root of PerlIO::* name space</p>
<a name="SYNOPSIS"></a><h1>SYNOPSIS</h1>
<pre class="verbatim">  <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><span class="i">$fh</span><span class="cm">,</span><span class="q">&quot;&lt;:crlf&quot;</span><span class="cm">,</span> <span class="q">&quot;my.txt&quot;</span><span class="s">)</span><span class="sc">;</span> <span class="c"># support platform-native and CRLF text files</span></pre>
<pre class="verbatim">  <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><span class="i">$fh</span><span class="cm">,</span><span class="q">&quot;&lt;&quot;</span><span class="cm">,</span><span class="q">&quot;his.jpg&quot;</span><span class="s">)</span><span class="sc">;</span>      <span class="c"># portably open a binary file for reading</span>
  <a class="l_k" href="functions/binmode.html">binmode</a><span class="s">(</span><span class="i">$fh</span><span class="s">)</span><span class="sc">;</span></pre>
<pre class="verbatim">  Shell:
    PERLIO=perlio perl ....</pre><a name="DESCRIPTION"></a><h1>DESCRIPTION</h1>
<p>When an undefined layer 'foo' is encountered in an <code class="inline"><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> layer specification then C code performs the equivalent of:</p>
<pre class="verbatim">  <a class="l_k" href="functions/use.html">use</a> <span class="w">PerlIO</span> <span class="q">&#39;foo&#39;</span><span class="sc">;</span></pre>
<p>The perl code in PerlIO.pm then attempts to locate a layer by doing</p>
<pre class="verbatim">  <a class="l_k" href="functions/require.html">require</a> <span class="w">PerlIO::foo</span><span class="sc">;</span></pre>
<p>Otherwise the <code class="inline"><span class="w">PerlIO</span></code>
 package is a place holder for additional
PerlIO related functions.</p>
<p>The following layers are currently defined:</p>
<ul>
<li><a name="%3aunix"></a><b>:unix</b>
<p>Lowest level layer which provides basic PerlIO operations in terms of
UNIX/POSIX numeric file descriptor calls
(open(), read(), write(), lseek(), close()).</p>
</li>
<li><a name="%3astdio"></a><b>:stdio</b>
<p>Layer which calls <code class="inline"><span class="w">fread</span></code>
, <code class="inline"><span class="w">fwrite</span></code>
 and <code class="inline"><span class="w">fseek</span></code>
/<code class="inline"><span class="w">ftell</span></code>
 etc.  Note
that as this is "real" stdio it will ignore any layers beneath it and
got straight to the operating system via the C library as usual.</p>
</li>
<li><a name="%3aperlio"></a><b>:perlio</b>
<p>A from scratch implementation of buffering for PerlIO. Provides fast
access to the buffer for <code class="inline"><span class="w">sv_gets</span></code>
 which implements perl's readline/&lt;&gt;
and in general attempts to minimize data copying.</p>
<p><code class="inline"><span class="j">:</span><span class="w">perlio</span></code>
 will insert a <code class="inline"><span class="j">:</span><span class="w">unix</span></code>
 layer below itself to do low level IO.</p>
</li>
<li><a name="%3acrlf"></a><b>:crlf</b>
<p>A layer that implements DOS/Windows like CRLF line endings.  On read
converts pairs of CR,LF to a single "\n" newline character.  On write
converts each "\n" to a CR,LF pair.  Note that this layer likes to be
one of its kind: it silently ignores attempts to be pushed into the
layer stack more than once.</p>
<p>It currently does <i>not</i> mimic MS-DOS as far as treating of Control-Z
as being an end-of-file marker.</p>
<p>(Gory details follow) To be more exact what happens is this: after
pushing itself to the stack, the <code class="inline"><span class="j">:</span><span class="w">crlf</span></code>
 layer checks all the layers
below itself to find the first layer that is capable of being a CRLF
layer but is not yet enabled to be a CRLF layer.  If it finds such a
layer, it enables the CRLFness of that other deeper layer, and then
pops itself off the stack.  If not, fine, use the one we just pushed.</p>
<p>The end result is that a <code class="inline"><span class="j">:</span><span class="w">crlf</span></code>
 means "please enable the first CRLF
layer you can find, and if you can't find one, here would be a good
spot to place a new one."</p>
<p>Based on the <code class="inline"><span class="j">:</span><span class="w">perlio</span></code>
 layer.</p>
</li>
<li><a name="%3ammap"></a><b>:mmap</b>
<p>A layer which implements "reading" of files by using <code class="inline"><span class="i">mmap</span><span class="s">(</span><span class="s">)</span></code>
 to
make (whole) file appear in the process's address space, and then
using that as PerlIO's "buffer". This <i>may</i> be faster in certain
circumstances for large files, and may result in less physical memory
use when multiple processes are reading the same file.</p>
<p>Files which are not <code class="inline"><span class="i">mmap</span><span class="s">(</span><span class="s">)</span></code>
-able revert to behaving like the <code class="inline"><span class="j">:</span><span class="w">perlio</span></code>

layer. Writes also behave like <code class="inline"><span class="j">:</span><span class="w">perlio</span></code>
 layer as <code class="inline"><span class="i">mmap</span><span class="s">(</span><span class="s">)</span></code>
 for write
needs extra house-keeping (to extend the file) which negates any advantage.</p>
<p>The <code class="inline"><span class="j">:</span><span class="w">mmap</span></code>
 layer will not exist if platform does not support <code class="inline"><span class="i">mmap</span><span class="s">(</span><span class="s">)</span></code>
.</p>
</li>
<li><a name="%3autf8"></a><b>:utf8</b>
<p>Declares that the stream accepts perl's <i>internal</i> encoding of
characters.  (Which really is UTF-8 on ASCII machines, but is
UTF-EBCDIC on EBCDIC machines.)  This allows any character perl can
represent to be read from or written to the stream. The UTF-X encoding
is chosen to render simple text parts (i.e.  non-accented letters,
digits and common punctuation) human readable in the encoded file.</p>
<p>Here is how to write your native data out using UTF-8 (or UTF-EBCDIC)
and then read it back in.</p>
<pre class="verbatim">	<a class="l_k" href="functions/open.html">open</a><span class="s">(</span><span class="w">F</span><span class="cm">,</span> <span class="q">&quot;&gt;:utf8&quot;</span><span class="cm">,</span> <span class="q">&quot;data.utf&quot;</span><span class="s">)</span><span class="sc">;</span>
	<a class="l_k" href="functions/print.html">print</a> <span class="i">F</span> <span class="i">$out</span><span class="sc">;</span>
	<a class="l_k" href="functions/close.html">close</a><span class="s">(</span><span class="w">F</span><span class="s">)</span><span class="sc">;</span></pre>
<pre class="verbatim">	<a class="l_k" href="functions/open.html">open</a><span class="s">(</span><span class="w">F</span><span class="cm">,</span> <span class="q">&quot;&lt;:utf8&quot;</span><span class="cm">,</span> <span class="q">&quot;data.utf&quot;</span><span class="s">)</span><span class="sc">;</span>
	<span class="i">$in</span> = <span class="q">&lt;F&gt;</span><span class="sc">;</span>
	<a class="l_k" href="functions/close.html">close</a><span class="s">(</span><span class="w">F</span><span class="s">)</span><span class="sc">;</span></pre>
<p>Note that this layer does not validate byte sequences. For reading
input, using <code class="inline"><span class="j">:</span><span class="i">encoding</span><span class="s">(</span><span class="w">utf8</span><span class="s">)</span></code>
 instead of bare <code class="inline"><span class="j">:</span><span class="w">utf8</span></code>
, is strongly
recommended.</p>
</li>
<li><a name="%3abytes"></a><b>:bytes</b>
<p>This is the inverse of <code class="inline"><span class="j">:</span><span class="w">utf8</span></code>
 layer. It turns off the flag
on the layer below so that data read from it is considered to
be "octets" i.e. characters in range 0..255 only. Likewise
on output perl will warn if a "wide" character is written
to a such a stream.</p>
</li>
<li><a name="%3araw"></a><b>:raw</b>
<p>The <code class="inline"><span class="j">:</span><span class="w">raw</span></code>
 layer is <i>defined</i> as being identical to calling
<code class="inline"><a class="l_k" href="functions/binmode.html">binmode($fh)</a></code> - the stream is made suitable for passing binary data
i.e. each byte is passed as-is. The stream will still be
buffered.</p>
<p>In Perl 5.6 and some books the <code class="inline"><span class="j">:</span><span class="w">raw</span></code>
 layer (previously sometimes also
referred to as a "discipline") is documented as the inverse of the
<code class="inline"><span class="j">:</span><span class="w">crlf</span></code>
 layer. That is no longer the case - other layers which would
alter binary nature of the stream are also disabled.  If you want UNIX
line endings on a platform that normally does CRLF translation, but still
want UTF-8 or encoding defaults the appropriate thing to do is to add
<code class="inline"><span class="j">:</span><span class="w">perlio</span></code>
 to PERLIO environment variable.</p>
<p>The implementation of <code class="inline"><span class="j">:</span><span class="w">raw</span></code>
 is as a pseudo-layer which when "pushed"
pops itself and then any layers which do not declare themselves as suitable
for binary data. (Undoing :utf8 and :crlf are implemented by clearing
flags rather than popping layers but that is an implementation detail.)</p>
<p>As a consequence of the fact that <code class="inline"><span class="j">:</span><span class="w">raw</span></code>
 normally pops layers
it usually only makes sense to have it as the only or first element in
a layer specification.  When used as the first element it provides
a known base on which to build e.g.</p>
<pre class="verbatim">    <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><span class="i">$fh</span><span class="cm">,</span><span class="q">&quot;:raw:utf8&quot;</span><span class="cm">,</span>...<span class="s">)</span></pre>
<p>will construct a "binary" stream, but then enable UTF-8 translation.</p>
</li>
<li><a name="%3apop"></a><b>:pop</b>
<p>A pseudo layer that removes the top-most layer. Gives perl code
a way to manipulate the layer stack. Should be considered
as experimental. Note that <code class="inline"><span class="j">:</span><a class="l_k" href="functions/pop.html">pop</a></code>
 only works on real layers
and will not undo the effects of pseudo layers like <code class="inline"><span class="j">:</span><span class="w">utf8</span></code>
.
An example of a possible use might be:</p>
<pre class="verbatim">    <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><span class="i">$fh</span><span class="cm">,</span>...<span class="s">)</span>
    ...
    <a class="l_k" href="functions/binmode.html">binmode</a><span class="s">(</span><span class="i">$fh</span><span class="cm">,</span><span class="q">&quot;:encoding(...)&quot;</span><span class="s">)</span><span class="sc">;</span>  <span class="c"># next chunk is encoded</span>
    ...
    <a class="l_k" href="functions/binmode.html">binmode</a><span class="s">(</span><span class="i">$fh</span><span class="cm">,</span><span class="q">&quot;:pop&quot;</span><span class="s">)</span><span class="sc">;</span>            <span class="c"># back to un-encoded</span></pre>
<p>A more elegant (and safer) interface is needed.</p>
</li>
<li><a name="%3awin32"></a><b>:win32</b>
<p>On Win32 platforms this <i>experimental</i> layer uses native "handle" IO
rather than unix-like numeric file descriptor layer. Known to be
buggy as of perl 5.8.2.</p>
</li>
</ul>
<a name="Custom-Layers"></a><h2>Custom Layers</h2>
<p>It is possible to write custom layers in addition to the above builtin
ones, both in C/XS and Perl.  Two such layers (and one example written
in Perl using the latter) come with the Perl distribution.</p>
<ul>
<li><a name="%3aencoding"></a><b>:encoding</b>
<p>Use <code class="inline"><span class="j">:</span><span class="i">encoding</span><span class="s">(</span><span class="w">ENCODING</span><span class="s">)</span></code>
 either in open() or binmode() to install
a layer that does transparently character set and encoding transformations,
for example from Shift-JIS to Unicode.  Note that under <code class="inline"><span class="w">stdio</span></code>

an <code class="inline"><span class="j">:</span><span class="w">encoding</span></code>
 also enables <code class="inline"><span class="j">:</span><span class="w">utf8</span></code>
.  See <a href="PerlIO/encoding.html">PerlIO::encoding</a>
for more information.</p>
</li>
<li><a name="%3avia"></a><b>:via</b>
<p>Use <code class="inline"><span class="j">:</span><span class="i">via</span><span class="s">(</span><span class="w">MODULE</span><span class="s">)</span></code>
 either in open() or binmode() to install a layer
that does whatever transformation (for example compression /
decompression, encryption / decryption) to the filehandle.
See <a href="PerlIO/via.html">PerlIO::via</a> for more information.</p>
</li>
</ul>
<a name="Alternatives-to-raw"></a><h2>Alternatives to raw</h2>
<p>To get a binary stream an alternate method is to use:</p>
<pre class="verbatim">    <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><span class="i">$fh</span><span class="cm">,</span><span class="q">&quot;whatever&quot;</span><span class="s">)</span>
    <a class="l_k" href="functions/binmode.html">binmode</a><span class="s">(</span><span class="i">$fh</span><span class="s">)</span><span class="sc">;</span></pre>
<p>this has advantage of being backward compatible with how such things have
had to be coded on some platforms for years.</p>
<p>To get an un-buffered stream specify an unbuffered layer (e.g. <code class="inline"><span class="j">:</span><span class="w">unix</span></code>
)
in the open call:</p>
<pre class="verbatim">    <a class="l_k" href="functions/open.html">open</a><span class="s">(</span><span class="i">$fh</span><span class="cm">,</span><span class="q">&quot;&lt;:unix&quot;</span><span class="cm">,</span><span class="i">$path</span><span class="s">)</span></pre>
<a name="Defaults-and-how-to-override-them"></a><h2>Defaults and how to override them</h2>
<p>If the platform is MS-DOS like and normally does CRLF to "\n"
translation for text files then the default layers are :</p>
<pre class="verbatim">  <span class="w">unix</span> <span class="w">crlf</span></pre>
<p>(The low level "unix" layer may be replaced by a platform specific low
level layer.)</p>
<p>Otherwise if <code class="inline"><span class="w">Configure</span></code>
 found out how to do "fast" IO using system's
stdio, then the default layers are:</p>
<pre class="verbatim">  <span class="w">unix</span> <span class="w">stdio</span></pre>
<p>Otherwise the default layers are</p>
<pre class="verbatim">  <span class="w">unix</span> <span class="w">perlio</span></pre>
<p>These defaults may change once perlio has been better tested and tuned.</p>
<p>The default can be overridden by setting the environment variable
PERLIO to a space separated list of layers (<code class="inline"><span class="w">unix</span></code>
 or platform low
level layer is always pushed first).</p>
<p>This can be used to see the effect of/bugs in the various layers e.g.</p>
<pre class="verbatim">  cd .../perl/t
  PERLIO=stdio  ./perl harness
  PERLIO=perlio ./perl harness</pre><p>For the various value of PERLIO see <a href="perlrun.html#PERLIO">"PERLIO" in perlrun</a>.</p>
<a name="Querying-the-layers-of-filehandles"></a><h2>Querying the layers of filehandles</h2>
<p>The following returns the <b>names</b> of the PerlIO layers on a filehandle.</p>
<pre class="verbatim">   <a class="l_k" href="functions/my.html">my</a> <span class="i">@layers</span> = <span class="i">PerlIO::get_layers</span><span class="s">(</span><span class="i">$fh</span><span class="s">)</span><span class="sc">;</span> <span class="c"># Or FH, *FH, &quot;FH&quot;.</span></pre>
<p>The layers are returned in the order an open() or binmode() call would
use them.  Note that the "default stack" depends on the operating
system and on the Perl version, and both the compile-time and
runtime configurations of Perl.</p>
<p>The following table summarizes the default layers on UNIX-like and
DOS-like platforms and depending on the setting of the <code class="inline"><span class="i">$ENV</span>{<span class="w">PERLIO</span>}</code>
:</p>
<pre class="verbatim"> PERLIO     UNIX-like                   DOS-like
 ------     ---------                   --------
 unset / "" unix perlio / stdio [1]     unix crlf
 stdio      unix perlio / stdio [1]     stdio
 perlio     unix perlio                 unix perlio
 mmap       unix mmap                   unix mmap</pre><pre class="verbatim"> <span class="c"># [1] &quot;stdio&quot; if Configure found out how to do &quot;fast stdio&quot; (depends</span>
 <span class="c"># on the stdio implementation) and in Perl 5.8, otherwise &quot;unix perlio&quot;</span></pre>
<p>By default the layers from the input side of the filehandle is
returned, to get the output side use the optional <code class="inline"><span class="w">output</span></code>
 argument:</p>
<pre class="verbatim">   <a class="l_k" href="functions/my.html">my</a> <span class="i">@layers</span> = <span class="i">PerlIO::get_layers</span><span class="s">(</span><span class="i">$fh</span><span class="cm">,</span> <span class="w">output</span> <span class="cm">=&gt;</span> <span class="n">1</span><span class="s">)</span><span class="sc">;</span></pre>
<p>(Usually the layers are identical on either side of a filehandle but
for example with sockets there may be differences, or if you have
been using the <code class="inline"><a class="l_k" href="functions/open.html">open</a></code> pragma.)</p>
<p>There is no set_layers(), nor does get_layers() return a tied array
mirroring the stack, or anything fancy like that.  This is not
accidental or unintentional.  The PerlIO layer stack is a bit more
complicated than just a stack (see for example the behaviour of <code class="inline"><span class="j">:</span><span class="w">raw</span></code>
).
You are supposed to use open() and binmode() to manipulate the stack.</p>
<p><b>Implementation details follow, please close your eyes.</b></p>
<p>The arguments to layers are by default returned in parenthesis after
the name of the layer, and certain layers (like <code class="inline"><span class="w">utf8</span></code>
) are not real
layers but instead flags on real layers: to get all of these returned
separately use the optional <code class="inline"><span class="w">details</span></code>
 argument:</p>
<pre class="verbatim">   <a class="l_k" href="functions/my.html">my</a> <span class="i">@layer_and_args_and_flags</span> = <span class="i">PerlIO::get_layers</span><span class="s">(</span><span class="i">$fh</span><span class="cm">,</span> <span class="w">details</span> <span class="cm">=&gt;</span> <span class="n">1</span><span class="s">)</span><span class="sc">;</span></pre>
<p>The result will be up to be three times the number of layers:
the first element will be a name, the second element the arguments
(unspecified arguments will be <code class="inline"><a class="l_k" href="functions/undef.html">undef</a></code>), the third element the flags,
the fourth element a name again, and so forth.</p>
<p><b>You may open your eyes now.</b></p>
<a name="AUTHOR"></a><h1>AUTHOR</h1>
<p>Nick Ing-Simmons &lt;nick@ing-simmons.net&gt;</p>
<a name="SEE-ALSO"></a><h1>SEE ALSO</h1>
<p><a href="functions/binmode.html">binmode</a>, <a href="functions/open.html">open</a>, <a href="perlunicode.html">perlunicode</a>, <a href="perliol.html">perliol</a>,
<a href="Encode.html">Encode</a></p>
</div>
      <div id="contentFooter"><a href="http://www.perl.org"><img src="perlpowered.png" border=0></a></div>
    </div>
  </div>

  <div id="right">
    <div id="rightContent">
      <div id="leftClose">
        <a href="#" onClick="closeRight()" title="Hide toolbar" onmouseover="rightCloseIcon.src='close_purple.gif';" onmouseout="rightCloseIcon.src='close_blue.gif';"><img src="close_blue.gif" name="rightCloseIcon" id="rightCloseIcon" border=0></a>
      </div>
      <h1>Search:</h1>
      <p>
        <form action="search.html" name="perldoc_search">
	  <input type="text" name="q" size="10" class="grey"><br>
	  <!--<select name="r"><option value="1" selected>Go to top result<option value="0">Show results list</select>-->
	</form>
      </p>
      <script language="JavaScript" type="text/javascript" src="/perl-version.js"></script>
      <h2>Labels:</h2>
      <p>
        <a href="#" onClick="addLabel('PerlIO','PerlIO.html')">Add this page</a>
      </p>
      <div class="labels" id="labels">
      </div>
    </div>
  </div>

</div>

</body>
</html>