ClassHelper.org US Site  ClassHelper.org UK Site  
ClassHelper News
About ClassHelper.org
Our Education Blog
Free Math Resources
Free School Clip Art
Crossword Puzzles
Word Find Puzzles
Cryptogram Puzzles
Word Jumble Puzzles
Coloring Book Pages
Computer Science
View Our Sitemap
Privacy Policy

Valid XHTML 1.0 Transitional


Perl Logo

Learn Perl - An Introduction to Perl Programming

Phil Paradis

By Philip C. Paradis
January 20, 2009

Table of Contents
  1. Introduction and Motivation
  2. System Requirements and Getting Perl
  3. Variables and Data Types
  4. Program Flow Control
  5. File Input/Output
  6. Subroutines and Code Reuse
  7. Your First Web Application
  8. Getting User Input with HTML Forms
  9. Coding Style and Maintenance
  10. Security Considerations
  11. Additional Programming Resources

Introduction and Motivation

Welcome to my beginner's tutorial on programming in Perl! If you're still reading this, you probably have at least a passing interest in computer programming, the Perl language, or web development. If this doesn't describe you, you're probably looking for something else. If you're a seasoned Perl developer, or you're looking for advanced Perl recipes to solve problems like world hunger, this tutorial probably won't interest you. If, however, you're a fairly computer-savvy individual looking for a basic introduction to Perl and programming in general, read on.

Since you're still here, let's begin. Perl is a computer programming language; the name stands for "Practical Extraction and Reporting Language", originally created by Larry Wall. Like all programming languages, Perl allows you to create programs that tell a computer how to perform a particular set of tasks. The operating system you're using (Windows, Linux, MacOS, etc) was created by programmers, along with the web browser you're using to view this page. These are examples of rather large programming projects, well beyond the scope of this tutorial. My goal is to help you understand what programming languages are, and how to use Perl to get a start writing your own programs.

This material has been tested on a Linode Linux VPS (ClassHelper has been hosted on a Linode for years). If you don't have your own server, get a Linode today. As a disclaimer, I do work for Linode, but I was a very satisfied customer for over five years prior to joining the company.

What is a program, and how is one designed?

Essentially, a program can be viewed as a series of instructions that describe how a computer is supposed to perform a series of tasks. Programs are most commonly written in higher-level langauges like Perl, which allows programmers to easily express the steps taken to achieve a goal. The goal might be as simple as printing a single line of text on a computer screen, or as complex as analyzing a genetic database. No matter how big or small programs may be, they all follow the same basic set of rules.

Let's say you want to make a basic breakfast of eggs. You could break down the process into steps as follows:

  1. Remove a carton of eggs from the refrigerator.
  2. Select an egg from the carton.
  3. Break the egg into a mixing bowl.
  4. Repeat step (2) until the desired number of eggs are in the bowl.
  5. If the carton still contains eggs, put it back in the refrigerator.
  6. If the carton is empty, discard it.
  7. Beat the eggs with a fork.
  8. Heat a skillet on the stove.
  9. Pour the eggs into the skillet.
  10. Stir the eggs around until they are sufficiently cooked.
  11. Dump the eggs onto plate.
  12. Enjoy your breakfast.
  13. Wash the dishes.

A programmer's job is fairly simple: define the objective, identify the tools and materials required, and break down the process into a series of steps. When designing a program, many programmers will compose a list that resembles our breakfast example, a process known as "writing pseudo-code." Pseudo-code can be a list of steps like our example (plain English), or it can more closely resemble actual software code. The choice is yours.

Is Perl the right tool for the job?

Programming languages like Perl serve as an interface between the programmer and the "bare metal" of the computer. They allow programmers to design programs in languages that more closely resemble English than bare machine code (the ones and zeros of binary). This greatly accelerates software development, and allows other programmers to maintain the codebase in the future. Perl's syntax borrows heavily from other languages, such as C and Pascal. An important difference is the fact that most Perl programs are interpreted rather than compiled to native machine code before execution, which means your program is loaded by the Perl interpreter on your computer and compiled into memory before it runs. This means that some programs written in Perl will execute more slowly than compiled applications, depending on the program and computer environment in question. If raw speed is your objective (say, for scientific computing), Perl may not be the best tool for the job. If you need to write a web application that will run under the Apache web server with mod_perl, Perl can be a very good choice.

In our next section, we'll learn about what you'll need to get started with Perl programming.

Continue: System Requirements and Getting Perl