📄 ch21_02.htm
字号:
<html><head><title>Internal Data Types (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="Internal Data Types"><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="ch21_01.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0"></a></td><td align="center" valign="top" width="171"><a href="ch21_01.htm">Chapter 21: Internals and Externals</a></td><td align="right" valign="top" width="172"><a href="ch21_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">21.2. Internal Data Types</h2><p><a name="INDEX-3678"></a><a name="INDEX-3679"></a><a name="INDEX-3680"></a><a name="INDEX-3681"></a><a name="INDEX-3682"></a><a name="INDEX-3683"></a><a name="INDEX-3684"></a><a name="INDEX-3685"></a><a name="INDEX-3686"></a><a name="INDEX-3687"></a><a name="INDEX-3688"></a>As the tree of opcodes constituting a compiled Perl program isexecuted, Perl values are created, manipulated, and destroyed. Thedata types you're familiar with in Perl all have corresponding datatypes in the C under Perl's hood, and you'll need to know about thosetypes when you pass data between the two languages.</p><p><a name="INDEX-3689"></a><a name="INDEX-3690"></a><a name="INDEX-3691"></a><a name="INDEX-3692"></a><a name="INDEX-3693"></a>Three C typedefs correspond to Perl's three basic data types: the <tt class="literal">SV</tt>(scalar value), <tt class="literal">AV</tt> (array value), and <tt class="literal">HV</tt> (hash value). In addition,an <tt class="literal">IV</tt> is a simple signed integer type guaranteed to be large enough to holdeither a pointer or an integer; and <tt class="literal">I32</tt> and <tt class="literal">I16</tt> are types guaranteed to be large enough to hold 32 bits and 16 bits, respectively. For storingunsigned versions of these last three typedefs, there exist <tt class="literal">UV</tt>, <tt class="literal">U32</tt>,and <tt class="literal">U16</tt> typedefs as well. All of these typedefs can be manipulatedwith the C functions described in the <em class="emphasis">perlguts</em> documentation.We sketch the behaviors of some of those functions below:</p><ul><li><p>There are four types of values that can be copied into an <tt class="literal">SV</tt>: aninteger value (<tt class="literal">IV</tt>), a double (<tt class="literal">NV</tt>), a string (<tt class="literal">PV</tt>), and another scalar(<tt class="literal">SV</tt>). There are dozens of functions for <tt class="literal">SV</tt>s to let you create,modify, grow, and check for the truth or definedness of the Perlscalars they represent. Perl references are implemented as an <tt class="literal">RV</tt>, aspecial type of <tt class="literal">SV</tt>.</p></li><li><p>When an <tt class="literal">AV</tt> is created, it can be created empty or populated with <tt class="literal">SV</tt>s,which makes sense since an array is a collection of scalars.</p></li><li><p>The <tt class="literal">HV</tt> has associated C functions for storing, fetching, deleting, andchecking for the existence of key/value pairs in the hash the <tt class="literal">HV</tt>represents.</p></li><li><p>There is also a <tt class="literal">GV</tt> (glob value), which can hold references to anyof the values associated with a variable identifier: a scalar value,an array value, a hash value, a subroutine, an I/O handle, or a format.</p></li></ul><p>When you extend Perl, you will sometimes need to know about thesevalues when you create bindings to C functions. When you embed Perl,you'll need to know about these values when you exchange data with thePerl interpreter included in your C program.</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="ch21_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="ch21_03.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0"></a></td></tr><tr><td align="left" valign="top" width="172">21.1. How Perl Works</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">21.3. Extending Perl (Using C from Perl)</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 + -