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

📄 ch03_05.htm

📁 编程珍珠,里面很多好用的代码,大家可以参考学习呵呵,
💻 HTM
字号:
<html><head><title>Ideographic Unary Operators (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="Ideographic Unary Operators"><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="ch03_04.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0"></a></td><td align="center" valign="top" width="171"><a href="ch03_01.htm">Chapter 3: Unary and Binary Operators</a></td><td align="right" valign="top" width="172"><a href="ch03_06.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0"></a></td></tr></table></div><hr width="515" align="left"><!-- SECTION BODY --><h2 class="sect1">3.5. Ideographic Unary Operators</h2><p><a name="INDEX-825"></a><a name="INDEX-826"></a>Most unary operators just have names (see <a href="ch03_10.htm#ch03-sect-nu">Section 3.10, "Named Unary and File Test Operators"</a> later in this chapter), but some operators are deemedimportant enough to merit their own special symbolic representation.All of these operators seem to have something to do with negation.Blame the mathematicians.</p><p><a name="INDEX-827"></a><a name="INDEX-828"></a><a name="INDEX-829"></a><a name="INDEX-830"></a> Unary <tt class="literal">!</tt> performslogical negation, that is, "not".  See <tt class="literal">not</tt> for alower precedence version of logical negation.  The value of a negatedoperand is true (1) if the operand is false (numeric 0, string<tt class="literal">"0"</tt>, the null string, or undefined) and false(<tt class="literal">""</tt>) if the operand is true.</p><p><a name="INDEX-831"></a><a name="INDEX-832"></a><a name="INDEX-833"></a><a name="INDEX-834"></a> Unary <tt class="literal">-</tt> performsarithmetic negation if the operand is numeric.  If the operand is anidentifier, a string consisting of a minus sign concatenated with theidentifier is returned.  Otherwise, if the string starts with a plusor minus, a string starting with the opposite sign is returned.  Oneeffect of these rules is that <tt class="literal">-bareword</tt> isequivalent to <tt class="literal">"-bareword"</tt>.  This is mostuseful for Tk programmers.</p><p><a name="INDEX-835"></a><a name="INDEX-836"></a><a name="INDEX-837"></a>Unary <tt class="literal">~</tt> performs bitwise negation, that is, 1's complement.  Bydefinition, this is somewhat nonportable when limited by the word sizeof your machine.  For example, on a 32-bit machine, <tt class="literal">~123</tt> is<tt class="literal">4294967172</tt>, while on a 64-bit machine, it's <tt class="literal">18446744073709551492</tt>.But you knew that already.</p><p>What you perhaps didn't know is that if the argument to<tt class="literal">~</tt> happens to be a string instead of a number, astring of identical length is returned, but with all the bits of thestring complemented.  This is a fast way to flip a lot of bits all atonce, and it's a way to flip those bits portably, since it doesn'tdepend on the word size of your computer.  Later we'll also cover thebitwise logical operators, which have string-oriented variants aswell.</p><p><a name="INDEX-838"></a>Unary <tt class="literal">+</tt> has no semantic effect whatsoever, even on strings.  It issyntactically useful for separating a function name from a parenthesizedexpression that would otherwise be interpreted as the complete list offunction arguments.  (See examples under the section <a href="ch03_01.htm#ch03-sect-tlo">Section 3.1, "Terms and List Operators (Leftward)"</a>.)  If you think about it sideways, <tt class="literal">+</tt> negates theeffect that parentheses have of turning prefix operators into functions.</p><p><a name="INDEX-839"></a> Unary <tt class="literal">\</tt> creates areference to whatever follows it.  Used on a list, it creates a listof references.  See the section <a href="ch08_02.htm#ch08-sect-bo">Section 3.2.1, "The Backslash Operator"</a> in <a href="ch08_01.htm">Chapter 8, "References"</a> for details.  Do not confuse thisbehavior with the behavior of backslash within a string, although bothforms do convey the vaguely negational notion of protecting the nextthing from interpretation.  This resemblance is not entirelyaccidental.</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="ch03_04.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="ch03_06.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0"></a></td></tr><tr><td align="left" valign="top" width="172">3.4. Exponentiation</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">3.6. Binding Operators</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 + -