PERL Handout — January 17 (due January 20)

Review Questions

  1. What are the four loop keywords?

 

 

 

 

2. How would you create an infinite loop with the for statement?

With the while statement?

 

3. What are the three keywords used in conditional statements?

 

  1. What is an alternate form of the following statement?

EXPRESSION if (CONDITION);

 

 

Exercises

  1. Use the while loop in a program to count from 1 to 100 in steps of 5.
  2. Use the for loop in a program to print each number from 55 to 1.
  3. (The next two are optional)

  4. Use an until loop, the next statement, and the modulus operator to loop from 0 to 100 and print out "AAA" every Sixteenth iteration.
  5. We looked at this program in class — you know what it does. Format the program to make it more readable, and comment it to explain HOW it works.

#!/usr/bin/perl

@a=(Lbzjoftt,Inqbujfodf,

Hvcsjt); $b="Lbssz Wbmm"

;$b =~ y/b-z/a-z/ ; $c =

" Tif ". @a ." hsfbu wj"

."suvft pg b qsphsbnnfs"

. ":\n";$c =~y/b-y/a-z/;

print"\n\n$c ";for($i=0;

$i<@a; $i++) { $a[$i] =~

y/b-y/a-z/;if($a[$i]eq$a

[-1]){print"and $a[$i]."

;}else{ print"$a[$i], ";

}}print"\n\t\t--$b\n\n";

You can find this program in my directory — here’s the path:

/usr/users3/grovesr/web/cgi-bin/larry.pl