📄 ch03_02.htm
字号:
<html><head><title>The Arrow Operator (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 & Associates, Inc."><meta name="DC.Source" content="" scheme="ISBN"><meta name="DC.Subject.Keyword" content=""><meta name="DC.Title" content="The Arrow Operator"><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_01.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_03.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.2. The Arrow Operator</h2><p><a name="INDEX-810"></a><a name="INDEX-811"></a><a name="INDEX-812"></a><a name="INDEX-813"></a><a name="INDEX-814"></a><a name="INDEX-815"></a><a name="INDEX-816"></a>Just as in C and C++, the binary<tt class="literal">-></tt> operator is an infix dereference operator.If the right side is a <tt class="literal">[...]</tt> array subscript, a<tt class="literal">{...}</tt> hash subscript, or a <tt class="literal">(...)</tt>subroutine argument list, the left side must be a reference (eitherhard or symbolic) to an array, a hash, or a subroutine, respectively.In an lvalue (assignable) context, if the left side is not areference, it must be a location capable of holding a hard reference,in which case such a reference will be<em class="emphasis">autovivified</em> for you. For more on this (and somewarnings about accidental autovivification) see <a href="ch08_01.htm">Chapter 8, "References"</a>.<blockquote><pre class="programlisting">$aref->[42] # an array dereference$href->{"corned beef"} # a hash dereference$sref->(1,2,3) # a subroutine dereference</pre></blockquote>Otherwise, it's a method call of some kind. The right side must be amethod name (or a simple scalar variable containing the method name), andthe left side must evaluate to either an object (a blessedreference) or a class name(that is, a package name):<blockquote><pre class="programlisting">$yogi = Bear->new("Yogi"); # a class method call$yogi->swipe($picnic); # an object method call</pre></blockquote>The method name may be qualified with a package name to indicate inwhich class to start searching for the method, or with the specialpackage name, <tt class="literal">SUPER::</tt>, to indicate that the search should start inthe parent class. See <a href="ch12_01.htm">Chapter 12, "Objects"</a>.</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_01.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_03.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0"></a></td></tr><tr><td align="left" valign="top" width="172">3.1. Terms and List Operators (Leftward)</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.3. Autoincrement and Autodecrement</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 © 2001</a> O'Reilly & 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 + -