Perl’s data types are simple. A scalar is a single thing. That’s it. You may know the term scalar from physics or mathematics or some other discipline, but Perl’s definition of the term is its own. It’s so important that we’ll say it again. A scalar is a single thing, and we use the word thing because we don’t have a better way to describe what Perl considers a scalar.
A scalar is the simplest kind of data that Perl
manipulates. Most scalars are either a number (like 255 or 3.25e20) or a
string of characters (like
hello or the
Gettysburg Address). Although you may think of numbers and strings as very
different things, Perl uses them nearly interchangeably.
If you have been using other programming languages, you’re probably
used to the idea of several different sorts of single items. C has
so on. Perl doesn’t make distinctions among single things, which is
something some people find hard to adjust to. However, as we’ll see in this
book, that allows us quite a bit of flexibility in dealing with data.
In this chapter, we show both scalar data, which are the values themselves, and scalar variables, which can store a scalar value. The distinction between these two is important. The value itself is fixed and we can’t change it. We can, however, change what we store in a variable (hence its name). Sometimes programmers are a bit sloppy with this and simply say “scalar.” We’ll be a bit sloppy too, except when it matters. This will be more important in ...