Best viewed with a modern CSS2-compliant browser, such as Mozilla Firefox.

Perl 5 Semantics

Scalars

Let's start with some terminology: A name is a perl expression which identifies a container, which is a storage unit that contains a value. This is best illustrated with a small example:

my $x = 42;

Here a new scalar container is produced, and the value 42 is placed inside it. After this statement and until end of scope, the name $x will refer to this particular container, unless shadowed by another my $x or our $x.

Note that the name $x may refer to a different container in other places in the program; and indeed that if this code is evaluated more than once then every time a new container is produced and named by $x. Every time the value of the container is 42, unless and until changed later on by another assignment to this container.

It is also possible for different names to name the same container. This is called aliasing. A common example is for ($x, $y, $z) where the loop variable $_ will alias the containers $x, $y, and $z successively.

There are four kinds of scalar values:

The undefined value: This is a special value used to represent "no value" at all. It's returned by undef and all scalar containers are set to it initially.

Simple values: Strings and numbers. More precisely, every simple value has a numeric aspect, a string aspect, or both. Normally you specify only one aspect of the value, and perl will add the other aspect if needed. In some special cases, the two aspects may be set separately, such as $! which holds an error code and an error message in its two aspects.

Reference values: A special kind of value that names a container, and will always continue to name that same container.

Glob values: Will be explained later.

Note that in perl, scalar values are never used directly, but are always within a scalar container. This is why \42 is valid: you can't get a reference to a value, but you can get one to the (temporary) container holding the 42.