On The First Steps

Perl is a massive language. It provides the basic data structures and syntactic constructs most high level programming languages have. In addition, it provides many extras such as a sophisticated pattern matching facility, many operators for handling files and directories, for network programming, and for interacting with the underlying operating system. On top of the large array of facilities the language itself provides, there are many packages and modules that are freely available for doing any task imaginable. It is both the built-in capabilities of Perl and the availability of a large number of well-written modules that have made Perl a popular language.

Perl is a glue language. The many capabilities that Perl provides may seem to be disconnected at first. However, Perl does an excellent job of putting the seemingly disparate parts into a coherent whole. Mastering Perl takes many years of programming experience. However, it is a language that is surprisingly easy to learn. It is not necessary to know all of its syntax to get started or to even write fairly sophisticated programs.

This chapter promptly immerses us in the immensity of Perl. We get introduced to syntactic features of Perl using simple examples. We illustrate the essential elements of the language in real programs, without getting bogged down in details and fine print. In this chapter, we are not trying to be complete or even precise, except that the examples we provide are correct and functional. We want the reader to get as quickly as possible to the point where the learner can write useful programs, and some fairly complex ones. As a consequence, we get into a few complex topics toward the end of the chapter. We feel that familiarity with some complex features in the beginning will excite a learner by increasing his or her level of curiosity. One does not have to be nervous if one does not understand all of the programs and discussions since we present the same issues at length later in the book. Since we do not use the full power of the language, the examples may not be as concise and elegant as they should be. In addition, later chapters necessarily repeat the ideas discussed in this chapter. We hope that the repetition helps one learn better.

A careful reading of this chapter will give the student a sense of accomplishment in a short period of time. Programmers experienced in one or more high level programming languages should be able to extrapolate from the material to their own programming needs. Beginners should supplement it by writing small, similar programs of their own. The best way to learn any programming language is to understand the motivation behind example programs, read them, understand them, sit at a computer, type in the sample examples, and finally code on one’s own. That is why the chapters in this book have many example programs.

In this book, when we talk about Unix or Unix-like systems, we not only mean varieties of Unix available, but also include Unix-like systems such as Linux or Macintosh OS X, or simulation of Unix in Windows systems such as cygwin. When we talk about non-Unix systems, we mean varieties of Windows operating systems from Microsoft, Inc., and pre-OS X versions of Macintosh OS from Apple Computer, Inc.