home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Book Home Programming PerlSearch this book

21.2. Internal Data Types

As the tree of opcodes constituting a compiled Perl program is executed, Perl values are created, manipulated, and destroyed. The data types you're familiar with in Perl all have corresponding data types in the C under Perl's hood, and you'll need to know about those types when you pass data between the two languages.

Three C typedefs correspond to Perl's three basic data types: the SV (scalar value), AV (array value), and HV (hash value). In addition, an IV is a simple signed integer type guaranteed to be large enough to hold either a pointer or an integer; and I32 and I16 are types guaranteed to be large enough to hold 32 bits and 16 bits, respectively. For storing unsigned versions of these last three typedefs, there exist UV, U32, and U16 typedefs as well. All of these typedefs can be manipulated with the C functions described in the perlguts documentation. We sketch the behaviors of some of those functions below:

  • There are four types of values that can be copied into an SV: an integer value (IV), a double (NV), a string (PV), and another scalar (SV). There are dozens of functions for SVs to let you create, modify, grow, and check for the truth or definedness of the Perl scalars they represent. Perl references are implemented as an RV, a special type of SV.

  • When an AV is created, it can be created empty or populated with SVs, which makes sense since an array is a collection of scalars.

  • The HV has associated C functions for storing, fetching, deleting, and checking for the existence of key/value pairs in the hash the HV represents.

  • There is also a GV (glob value), which can hold references to any of 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.

When you extend Perl, you will sometimes need to know about these values when you create bindings to C functions. When you embed Perl, you'll need to know about these values when you exchange data with the Perl interpreter included in your C program.



Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.