Node:Working with Scalars, Next:, Previous:Getting Started, Up:Top



Working with Scalars

Scalar data are the most basic in Perl. Each scalar datum is logically a single entity. Scalars can be strings of characters or numbers. In Perl, you write literal scalar strings like this:

For example, the strings "foobar" and 'baz' are scalar data. The numbers 3, 3.5 and -1 are also scalar data.

Strings are always enclosed in some sort of quoting, the most common of which are single quotes, '', and and double quotes, "". We'll talk later about how these differ, but for now, you can keep in mind that any string of characters inside either type of quotes are scalar string data.

Numbers are always written without quotes. Any numeric sequence without quotes are scalar number data.

In this chapter, we will take a look at the variety of scalar data available in Perl, the way to store them in variables, how to operate on them, and how to output them.