Perl Programming   «Prev  Next»
Lesson 1

Basic Perl Programming

This course is for anyone who needs a results-oriented introduction to Perl 5.
It is designed to give you a solid background in the Perl language, covering all of its major features and functions.

Origins of Perl Programming Language

Perl was originally developed as a language to replace awk and sed in Unix system administration.
It has since become the defacto language for web programming as well, and today it is hard to find a system that is not using Perl for one purpose or another. Perl is a scripting language which means that it runs directly from the source code and there is no separate compilation process. But, it is not a strictly interpreted language either. The program perl actually compiles much of the source code into an intermediate byte code which is then optimized before running. The effect is a language with many of the advantages of both interpreters and compilers. With its flexible syntax, rich regular expressions and full library of internal functions, Perl has allowed me to open up my creativity as a programmer. I hope it does the same for you.
  • Perl History: Perl was originally developed by Larry Wall in 1987 as a general-purpose Unix scripting language to make report processing easier. Since then, it has undergone many changes and revisions. Perl 6, which began as a redesign of Perl 5 in 2000, eventually evolved into a separate language and both languages continue to be developed independently by different development teams. The Perl languages borrow features from other programming languages including
    1. C,
    2. shell script (sh),
    3. AWK, and
    4. sed.
They provide powerful text processing facilities without the arbitrary data-length limits of many contemporary Unix commandline tools, facilitating easy manipulation of text files. Perl 5 gained widespread popularity in the late 1990s as a CGI scripting language, in part due to its regular expression and string parsing capabilities.


Perl Course Goals

By working through the course lessons and exercises, you will gain the skills you need to:
  1. Write effective Perl programs for common system-administration tasks
  2. Take advantage of regular expressions--even in other languages
  3. Understand, use, and modify Perl programs written by other people
  4. Create quick, one-liner programs for simple everyday tasks
  5. Move on to the next course in the Programming in Perl Series, Perl for the Web.

Before we actually start, take a few minutes to go over the following:
  • Perl Course Prerequisites: Since Perl is based on awk, sed, sh, and C, if you know one or more of those languages, you may be in a position to learn Perl faster, but it's not really necessary that you know them. If your programming experience is limited, you might havfe to take a little more time with each lesson. Because Perl was written for Unix (and has been ported to other operating systems), some knowledge of Unix is also helpful, but not necessary. Again, if you have no Unix experience, some of the concepts may be foreign to you, but they should not be insurmountably so.
  • AWK: Several kinds of tasks occur repeatedly when working with text files. You might want to extract certain lines and discard the rest. Or you may need to make changes wherever certain patterns appear, but leave the rest of the file alone. Such jobs are often easy with awk. The awk utility interprets a special-purpose programming language that makes it easy to handle simple data-reformatting jobs.
    The GNU implementation of awk is called gawk; if you invoke it with the proper options or environment variables, it is fully compatible with the POSIX[1] specification of the awk language and with the Unix version of awk maintained by Brian Kernighan. This means that all properly written awk programs should work with gawk. So most of the time, we do not distinguish between gawk and other awk implementations.
    Using awk you can:
    1. Manage small, personal databases
    2. Generate reports
    3. Validate data
    4. Produce indexes and perform other document-preparation tasks
    5. Experiment with algorithms that you can adapt later to other computer languages

    In addition, gawk provides facilities that make it easy to:
    1. Extract bits and pieces of data for processing
    2. Sort data
    3. Perform simple network communications
    4. Profile and debug awk programs
    5. Extend the language with functions written in C or C++

Platform Support

This course is platform-independent and can be taken on any Win32, Mac, or Unix system. Platform-dependent instructions are provided throughout the course. Perl Scripts can be developed on a Win32 platform and the best environment on which to run your Perl Scripts is a Linux/Unix environment.
  1. What you will need for this course

Course Structure for Learning Perl

So you can start writing simple and effective Perl scripts as soon as possible, each of the lessons are short and direct, giving you the rich features of the perl language that you now want to learn. Perl was the language of choice before the advent of PHP. There are 6 modules and only the final module is Web-focused, explaining several example Perl programs useful for Web programming. The emphasis in Modules 1 through 5 is the Perl language.
In fact, even though Perl is native to the Unix-like operating systems, we have gone to great lengths to keep the examples as generic as possible so they will run on a wide variety of systems. Depending on your experience level, you can expect to spend 15 to 30 minutes on each lesson. Of course, you may want to spend more time on some lessons and less time on others, so consider this number a rough estimate.
Over the next six modules, we will cover:
  1. What the Perl language is
  2. How to run a Perl program
  3. Variables and data types
  4. Perl operators
  5. Regular expressions
  6. Flow control
  7. Perl functions and subroutines
  8. Some common applications in Perl


Perl was originally thought of as a natural enhancement for the popular csh shell script notation of Unix, Perl was at first primarily used for text manipulation. Its maturity in the early 1990s coincided with the rise of the Web, and it rapidly became the most popular programming language for HTML form processing and otherWeb development as well.
Perl has been called a "Swiss Army" knife for its features coupled with its considerable programming power and flexibility. The common phrase among hardened Perl programmers is: "There is more than one way to do it." Most programming goals can be achieved in Perl in at least three ways, depending on which language features and techniques the programmer prefers to use. It is not uncommon for an experienced Perl programmer to reach for the manual when reading code written by another programmer. Perl has also been called "duct tape for the Web", emphasizing its utility for producing applications, Web sites, and general program fixes for a wide variety of problems and domains.
In this module we give a brief history of Perl, including major events preceding the creation of Perl that set the historical stage for it. We provide an overview of the language, including example code to show how its features are used in practice. We discuss Web site programming in Perl using the CGI (Common Gateway Interface) standard and show several database interface methods in Perl.
In the next lesson, some of the features of the Perl Programming Language will be covered. Then, the following two lessons will walk you through the steps of downloading perl and installing it on your machine.

SEMrush Software