What Is a Reference?
In our example, $vitals[0]
has the value “john”. That is, it
contains a string that happens to be the name of another (global)
variable. We say that the first variable refers
to the second, and this sort of reference is called a
symbolic reference, since Perl has to look up @john in a symbol table to find it. (You
might think of symbolic references as analogous to symbolic links in
the filesystem.) We’ll talk about symbolic references later in this
chapter.
The other kind of reference is a hard
reference, and this is what most Perl programmers use to accomplish
their indirections (if not their indiscretions). We call them hard
references not because they’re difficult, but because they’re real and
solid. If you like, think of hard references as real references and
symbolic references as fake references. It’s like the difference
between true friendship and mere name-dropping. When we don’t specify
which type of reference we mean, it’s a hard reference. Figure 8-1 depicts a variable named $bar referring to the contents of a scalar
named $foo, which has the value
“bot”.

Figure 8-1. A hard reference and a symbolic reference
Unlike a symbolic reference, a real reference refers not to the name of another variable (which is just a container for a value) but to an actual value itself, some internal glob of data. There’s no good word for that thing, but when we have to, we’ll ...
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