Hour 3. Controlling the Program s Flow

 <  Day Day Up  >  

Hour 3. Controlling the Program's Flow

What You'll Learn in This Hour:

  • Block statements

  • Operators

  • Looping

  • Labels

  • Exiting Perl after a program execution

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 tasks ”over and over again ”without 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 tiresome ”not to mention silly ”if 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.

 <  Day Day Up  >  


SAMS Teach Yourself Perl in 24 Hours
Sams Teach Yourself Perl in 24 Hours (3rd Edition)
ISBN: 0672327937
EAN: 2147483647
Year: 2005
Pages: 241

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net