A View of the Internals
Let us now take a look inside Perl to understand how it manages memory. You can safely skip this section without loss of continuity.
A variable logically represents a binding between a name and a value, as Figure 1.3 illustrates.[13]

Figure 1-3. A variable is a name and value pair
An array or a hash is not just a collection of numbers or strings. It is a collection of scalar values, and this distinction is important, as Figure 1.4 illustrates.

Figure 1-4. An array value is a collection of scalar values
Each box in Figure 1.4 represents a distinct value. An array has one value that represents the collection of scalar values. Each element of the array is a distinct scalar value. This is analogous to a pride of lions being treated as a single entity (which is why we refer to it in the singular) that has properties distinct from those of the individual lion.
Notice also that while a name always points to a value, a value doesn’t always have to be pointed to by a name, as the array elements in Figure 1.4 or anonymous arrays and hashes exemplify.
Reference Counts
To support painless and transparent memory management, Perl maintains a reference count for every value, whether it is directly pointed to by a name or not. Let’s add this piece of information to our earlier ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access