Day 6. Conditionals and Loops

Finally, we come to conditionals and loops! You've already learned a fair amount about the more popular conditional, if, and about while loops, so you might have already deduced that conditionals and loops are used to control the execution of blocks of statements in Perl script. Without these structures, your script would run from top to bottom, executing each statement in turn until it got to the end. No testing to see if a value is true, and then branching to a different bit of code; no repeating the execution of a block of statements a number of times. Scripts would be very boring indeed without conditionals and loops. They're so important you had to actually start learning about them two days ago, before we even got to this lesson.

In this lesson, we'll discuss in detail the various conditional and loop constructs you have to work with in Perl, including

  • An introduction to block statements

  • The if and ifelse, ifelsif, and unless… conditionals

  • The while, dowhile, and until loops

  • The foreach and for loops

  • Controlling loops with next, last, redo, and labels

In addition, we'll also look at a two other topics that will build on your Perl knowledge, including

  • Using $_ (the default variable) as a shortcut for many operations

  • Reading input from files with <>

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.165.131