Install Perl 5.8.8
[msysgit.git] / mingw / html / lib / bytes.html
blob709264eaaa8377385bc7ae6a645f31098f9b39e2
1 <?xml version="1.0" ?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml">
4 <head>
5 <title>bytes - Perl pragma to force byte semantics rather than character semantics</title>
6 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
7 <link rev="made" href="mailto:" />
8 </head>
10 <body style="background-color: white">
11 <table border="0" width="100%" cellspacing="0" cellpadding="3">
12 <tr><td class="block" style="background-color: #cccccc" valign="middle">
13 <big><strong><span class="block">&nbsp;bytes - Perl pragma to force byte semantics rather than character semantics</span></strong></big>
14 </td></tr>
15 </table>
17 <p><a name="__index__"></a></p>
18 <!-- INDEX BEGIN -->
20 <ul>
22 <li><a href="#name">NAME</a></li>
23 <li><a href="#synopsis">SYNOPSIS</a></li>
24 <li><a href="#description">DESCRIPTION</a></li>
25 <li><a href="#limitations">LIMITATIONS</a></li>
26 <li><a href="#see_also">SEE ALSO</a></li>
27 </ul>
28 <!-- INDEX END -->
30 <hr />
31 <p>
32 </p>
33 <h1><a name="name">NAME</a></h1>
34 <p>bytes - Perl pragma to force byte semantics rather than character semantics</p>
35 <p>
36 </p>
37 <hr />
38 <h1><a name="synopsis">SYNOPSIS</a></h1>
39 <pre>
40 use bytes;
41 ... chr(...); # or bytes::chr
42 ... index(...); # or bytes::index
43 ... length(...); # or bytes::length
44 ... ord(...); # or bytes::ord
45 ... rindex(...); # or bytes::rindex
46 ... substr(...); # or bytes::substr
47 no bytes;</pre>
48 <p>
49 </p>
50 <hr />
51 <h1><a name="description">DESCRIPTION</a></h1>
52 <p>The <code>use bytes</code> pragma disables character semantics for the rest of the
53 lexical scope in which it appears. <code>no bytes</code> can be used to reverse
54 the effect of <code>use bytes</code> within the current lexical scope.</p>
55 <p>Perl normally assumes character semantics in the presence of character
56 data (i.e. data that has come from a source that has been marked as
57 being of a particular character encoding). When <code>use bytes</code> is in
58 effect, the encoding is temporarily ignored, and each string is treated
59 as a series of bytes.</p>
60 <p>As an example, when Perl sees <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_chr"><code>$x = chr(400)</code></a>, it encodes the character
61 in UTF-8 and stores it in $x. Then it is marked as character data, so,
62 for instance, <code>length $x</code> returns <code>1</code>. However, in the scope of the
63 <code>bytes</code> pragma, $x is treated as a series of bytes - the bytes that make
64 up the UTF8 encoding - and <code>length $x</code> returns <code>2</code>:</p>
65 <pre>
66 $x = chr(400);
67 print &quot;Length is &quot;, length $x, &quot;\n&quot;; # &quot;Length is 1&quot;
68 printf &quot;Contents are %vd\n&quot;, $x; # &quot;Contents are 400&quot;
70 use bytes; # or &quot;require bytes; bytes::length()&quot;
71 print &quot;Length is &quot;, length $x, &quot;\n&quot;; # &quot;Length is 2&quot;
72 printf &quot;Contents are %vd\n&quot;, $x; # &quot;Contents are 198.144&quot;
73 }</pre>
74 <p>chr(), ord(), substr(), <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_index"><code>index()</code></a> and <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_rindex"><code>rindex()</code></a> behave similarly.</p>
75 <p>For more on the implications and differences between character
76 semantics and byte semantics, see <a href="file://C|\msysgit\mingw\html/pod/perluniintro.html">the perluniintro manpage</a> and <a href="file://C|\msysgit\mingw\html/pod/perlunicode.html">the perlunicode manpage</a>.</p>
77 <p>
78 </p>
79 <hr />
80 <h1><a name="limitations">LIMITATIONS</a></h1>
81 <p>bytes::substr() does not work as an lvalue().</p>
82 <p>
83 </p>
84 <hr />
85 <h1><a name="see_also">SEE ALSO</a></h1>
86 <p><a href="file://C|\msysgit\mingw\html/pod/perluniintro.html">the perluniintro manpage</a>, <a href="file://C|\msysgit\mingw\html/pod/perlunicode.html">the perlunicode manpage</a>, <a href="file://C|\msysgit\mingw\html/lib/utf8.html">the utf8 manpage</a></p>
87 <table border="0" width="100%" cellspacing="0" cellpadding="3">
88 <tr><td class="block" style="background-color: #cccccc" valign="middle">
89 <big><strong><span class="block">&nbsp;bytes - Perl pragma to force byte semantics rather than character semantics</span></strong></big>
90 </td></tr>
91 </table>
93 </body>
95 </html>