Scalar Values
Whether it’s named directly or indirectly, and whether it’s in a variable, or an array element, or is just a temporary value, a scalar always contains a single value. This value may be a number, a string, or a reference to another piece of data. Or, there might even be no value at all, in which case the scalar is said to be undefined. Although we might speak of a scalar as “containing” a number or a string, scalars are typeless: you are not required to declare your scalars to be of type integer or floating point or string or whatever.
Future versions of Perl might allow you to insert int, num,
and str type declarations. This is
not to enforce strong typing, but to give the optimizer hints about
things that it might not figure out for itself. Some CPAN modules
already do this for you.
Perl stores strings as sequences of characters, with no
arbitrary constraints on length or content. In human terms, you don’t
have to decide in advance how long your strings are going to get, and
you can include any characters, including null bytes, within your
string. Perl stores numbers as signed (or unsigned) integers if
possible, or as double-precision floating-point values in the
machine’s native format otherwise. Floating-point values are not
infinitely precise. This is important to remember because comparisons
like (10/3 == 1/3*10) tend to fail
mysteriously.
However, you can swap out Perl’s normal notions of numbers using
the bigint, bigrat, and bignum pragmas. These provide integers, ...
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