Hour 2. Perl's Building Blocks: Numbers and Strings

Every programming language—and every human language—has a similar beginning: You have to have something to talk about. In Perl, numbers and strings are the basic unit of conversation, and these are called scalars.

Scalars are Perl's basic unit of conversation. Every hour in this book deals with scalars—increasing, decreasing, querying, testing, collecting, clearing, separating, folding, sorting, saving, loading, printing, and deleting them. Scalars are Perl's singular nouns; they can represent a word, a record, a document, a line of text, or a character.

Scalars in Perl can represent literal data, which does not change over the life of the program. Some programming languages call these values constants or literals. Literal data is used for things that simply do not change, such as the value of π, the rate of acceleration of a body falling to Earth, and the name of the 15th President of the United States. If these values are needed by a Perl program, they would, at some point in the program, be represented by a scalar literal.

The other kinds of scalars in Perl are those that change, called scalar variables. Variables hold data while you manipulate it. You can change the contents of variables because they merely act as handles for the data they represent. Variables are given names—convenient and easy-to-remember names, I hope—that help you refer to the data you are manipulating.

This hour also introduces Perl's operators. They are one kind of verb in the Perl language. Operators take Perl's nouns and do the actual manipulations you need to write programs that perform useful tasks.

In this hour, you'll learn about

  • Literal numbers and strings

  • Scalar variables

  • Operators

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.220.120.161