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, ...

Get Programming Perl, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.