HTML CSS PHP PERL

Hour 3. Controlling the Program's Flow

 
Previous Table of Contents Next

Hour 3. Controlling the Program's Flow

What You'll Learn in This Hour:

In Hour 2, "Perl's Building Blocks: Numbers and Strings," you learned about statements, operators, and expressions. All the examples in that hour had one thing in common: All the statements were executed in order from top to bottom and were executed only once.

One of the reasons that you use computers is that computers are very good at performing repetitive tasksover and over againwithout getting tired or bored and without developing carpal tunnel syndrome. So far, you haven't had any way of telling Perl to "do this task X times" or to "repeat this task until it's done." In this hour, you will learn about Perl's control structures. Using them, you can group statements into something called a statement block and run the group of statements repeatedly until they've done what you want.

The other chore that computers excel at is making decisions quickly. It would be tiresomenot to mention sillyif a computer had to ask you every time it made a decision. The very act of retrieving and reading your email causes your computer to make millions of decisions that you really don't want to deal with: how to assemble network traffic, which colors to make each pixel on your screen, how your incoming mail should be pulled apart and displayed, what should be done when your mouse cursor moves even a tiny bit, and countless others. All these decisions are made up of other decisions, and some of them are made thousands of times per second. In this hour, you will learn about conditional statements. Using these statements, you can write blocks of code that will be executed or not, depending on decisions made in your Perl program.

    Previous Table of Contents Next
    © 2000- NIV