⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch02_01.htm

📁 编程珍珠,里面很多好用的代码,大家可以参考学习呵呵,
💻 HTM
字号:
<html><head><title>Bits and Pieces (Programming Perl)</title><!-- STYLESHEET --><link rel="stylesheet" type="text/css" href="../style/style1.css"><!-- METADATA --><!--Dublin Core Metadata--><meta name="DC.Creator" content=""><meta name="DC.Date" content=""><meta name="DC.Format" content="text/xml" scheme="MIME"><meta name="DC.Generator" content="XSLT stylesheet, xt by James Clark"><meta name="DC.Identifier" content=""><meta name="DC.Language" content="en-US"><meta name="DC.Publisher" content="O'Reilly &amp; Associates, Inc."><meta name="DC.Source" content="" scheme="ISBN"><meta name="DC.Subject.Keyword" content=""><meta name="DC.Title" content="Bits and Pieces"><meta name="DC.Type" content="Text.Monograph"></head><body><!-- START OF BODY --><!-- TOP BANNER --><img src="gifs/smbanner.gif" usemap="#banner-map" border="0" alt="Book Home"><map name="banner-map"><AREA SHAPE="RECT" COORDS="0,0,466,71" HREF="index.htm" ALT="Programming Perl"><AREA SHAPE="RECT" COORDS="467,0,514,18" HREF="jobjects/fsearch.htm" ALT="Search this book"></map><!-- TOP NAV BAR --><div class="navbar"><table width="515" border="0"><tr><td align="left" valign="top" width="172"><a href="part2.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0"></a></td><td align="center" valign="top" width="171"><a href="part2.htm">Part 2: The Gory Details</a></td><td align="right" valign="top" width="172"><a href="ch02_02.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0"></a></td></tr></table></div><hr width="515" align="left"><!-- SECTION BODY --><h1 class="chapter">Chapter 2.  Bits and Pieces</h1><div class="htmltoc"><h4 class="tochead">Contents:</h4><p><a href="ch02_01.htm">Atoms</a><br><a href="ch02_02.htm">Molecules</a><br><a href="ch02_03.htm">Built-in Data Types</a><br><a href="ch02_04.htm">Variables</a><br><a href="ch02_05.htm">Names</a><br><a href="ch02_06.htm">Scalar Values</a><br><a href="ch02_07.htm">Context</a><br><a href="ch02_08.htm">List Values and Arrays</a><br><a href="ch02_09.htm">Hashes</a><br><a href="ch02_10.htm">Typeglobs and Filehandles</a><br><a href="ch02_11.htm">Input Operators</a><br></p></div><p>We're going to start small, so this chapter is about the elements of Perl.</p><p>Since we're starting small, the progression through the next severalchapters is necessarily from small to large.  That is, we take abottom-up approach, beginning with the smallest components of Perlprograms and building them into more elaborate structures, much likemolecules are built out of atoms.  The disadvantage of this approachis that you don't necessarily get the Big Picture before getting lostin a welter of details.  The advantage is that you can understand theexamples as we go along.  (If you're a top-down person, just turn thebook over and read the chapters backward.)</p><p>Each chapter does build on the preceding chapter (or the <em class="emphasis">subsequent</em>chapter, if you're reading backward), so you'll need to be careful ifyou're the sort of person who skips around.</p><p>You're certainly welcome to peek at the reference materials toward theend of the book as we go along.  (That doesn't count as skippingaround.)  In particular, any isolated word in <tt class="literal">typewriter</tt>font is likely to be found in <a href="ch29_01.htm">Chapter 29, "Functions"</a>.  Andalthough we've tried to stayoperating-system neutral, if you are unfamiliar with Unix terminologyand run into a word that doesn't seem to mean what you think it oughtto mean, you should check whether the word is in the Glossary.  If theGlossary doesn't work, the index probably will.</p><h2 class="sect1">2.1. Atoms</h2><p><a name="INDEX-401"></a><a name="INDEX-402"></a><a name="INDEX-403"></a>Although there are various invisible things going on behind the scenesthat we'll explain presently, the smallest things you generally work within Perl are individual characters.  And we do mean characters;historically, Perl freely confused bytes with characters and characterswith bytes, but in this new era of global networking, we must be carefulto distinguish the two.</p><p><a name="INDEX-404"></a>Perl may, of course, be written entirely in the 7-bit ASCIIcharacter set.  Perl also allows you to write in any 8-bit or 16-bitcharacter set, whether it's a national character set or some otherlegacy character set.  However, if you choose to write in one ofthese older, non-ASCII character sets, you may use non-ASCIIcharacters only within string literals.  You are responsible formaking sure that the semantics of your program are consistent withthe particular national character set you've chosen.  For instance,if you're using a 16-bit encoding for an Asian national characterset, keep in mind that Perl will generally think of each of yourcharacters as two bytes, not as one character.</p><p><a name="INDEX-405"></a><a name="INDEX-406"></a> As described in <a href="ch15_01.htm">Chapter 15, "Unicode"</a>, we've recently addedsupport for Unicode toPerl.<a href="#FOOTNOTE-1">[1]</a> This support is pervasivethroughout the language: you can use Unicode characters in identifiers(variable names and such) as well as within literal strings.  When youare using Unicode, you don't need to worry about how many bits orbytes it takes to represent a character.  Perl just pretends allUnicode characters are the same size (that is, size 1), even thoughany given character might be represented by multiple bytes internally.Perl normally represents Unicode internally as UTF-8, avariable-length encoding.  (For instance, a Unicode smiley character,U-263A, would be represented internally as a three-byte sequence.)</p><blockquote class="footnote"><a name="FOOTNOTE-1"></a><p>[1] As excited as we are about Unicode support, mostof our examples will be in ASCII, since not everyone has a decentUnicode editor yet.</p></blockquote><p>If you'll let us drive our analogy of the physical elements a bitfurther, characters are atomic in the same sense as the individualatoms of the various elements.  Yes, they're composed of smallerparticles known as bits and bytes, but if you break a character apart(in a character accelerator, no doubt), the individual bits and byteslose the distinguishing chemical properties of the character as awhole.  Just as neutrons are an implementation detail of the U-238atom, so too bytes are an implementation detail of the U-263A character.</p><p>So we'll be careful to say "characters" when we mean characters, and"bytes" when we mean bytes.  But we don't mean to scare you--you canstill do the good old-fashioned byte processing easily enough.  All youhave to do is tell Perl that you still want to think of bytes ascharacters.  You can do that with a <tt class="literal">use bytes</tt> pragma (see <a href="ch31_01.htm">Chapter 31, "Pragmatic Modules"</a>).  But even if you don't do that, Perl willstill do a pretty good job of keeping small characters in 8 bits whenyou expect it to.</p><p>So don't sweat the small stuff.  Let's move on to bigger and better things.</p><!-- BOTTOM NAV BAR --><hr width="515" align="left"><div class="navbar"><table width="515" border="0"><tr><td align="left" valign="top" width="172"><a href="part2.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0"></a></td><td align="center" valign="top" width="171"><a href="index.htm"><img src="../gifs/txthome.gif" alt="Home" border="0"></a></td><td align="right" valign="top" width="172"><a href="ch02_02.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0"></a></td></tr><tr><td align="left" valign="top" width="172">Part 2. The Gory Details</td><td align="center" valign="top" width="171"><a href="index/index.htm"><img src="../gifs/index.gif" alt="Book Index" border="0"></a></td><td align="right" valign="top" width="172">2.2. Molecules</td></tr></table></div><hr width="515" align="left"><!-- LIBRARY NAV BAR --><img src="../gifs/smnavbar.gif" usemap="#library-map" border="0" alt="Library Navigation Links"><p><font size="-1"><a href="copyrght.htm">Copyright &copy; 2001</a> O'Reilly &amp; Associates. All rights reserved.</font></p><map name="library-map"> <area shape="rect" coords="2,-1,79,99" href="../index.htm"><area shape="rect" coords="84,1,157,108" href="../perlnut/index.htm"><area shape="rect" coords="162,2,248,125" href="../prog/index.htm"><area shape="rect" coords="253,2,326,130" href="../advprog/index.htm"><area shape="rect" coords="332,1,407,112" href="../cookbook/index.htm"><area shape="rect" coords="414,2,523,103" href="../sysadmin/index.htm"></map><!-- END OF BODY --></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -