O'Reilly logo

Learning Perl, 7th Edition by Tom Phoenix, brian d foy, Randal L. Schwartz

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 2. Scalar Data

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 char, int, and 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required