Perl Value Types

In this section, we’ll study the functions and macros for manipulating the internal value types. We will also examine each object’s internal makeup in sections entitled “Inside SV,” “Inside AV,” and so on. Although they will help you in making seasoned judgments about memory overhead and performance, you can skip these sections if the detail weighs you down.

Scalar Values

A scalar value (SV) contains the value of the scalar, a reference count, and a bitmask to describe the state of the scalar. The scalar may be an integer value (“IV”), a double (“NV”), a string (“PV” for pointer value), a reference (“RV”), or a special-purpose object (“magical”). We’ll discuss magical variables separately.

Table 20.1 shows the functions and macros to create, delete, and modify SVs. They are listed in sv.h and implemented in sv.c. Macros, by convention, have their first letter capitalized. All the tables in this chapter make use of two important typedefs, I32 and U32, which represent signed and unsigned integral quantities that are at least 32 bits wide and big enough to hold a pointer (it will be 64 bits on a 64-bit machine).

Table 20-1. API for Scalar Values

Function/Macro

Description

SV* newSViv(I32);
SV* newSVnv(double);
SV* newSVpv(char* str,
            int   len);

Create a new SV from an integer, double, or string respectively. newSVpv calculates the length of the string if len is 0.

SV* newSVsv(SV *);

Create a clone of an existing SV. To create an empty SV, use the global scalar ...

Get Advanced Perl Programming 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.