Reference Basics

You create and assign a normal scalar variable by using an assignment operator, as follows:

$a="Stones";   # A normal scalar

After this snippet, a scalar variable called $a is created, and it contains the string "Stones". So far, nothing unusual. Now somewhere in the computer is a place labeled $a that contains that string, as illustrated here:

If you were to assign the scalar $b to $a—like $a=$b;—you would wind up with two copies of the data, with two different names, as shown here:

Having two copies might be okay if you ...

Get Sams Teach Yourself Perl in 24 Hours 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.