Question 4

Most people came pretty close to getting this.  The two most common
mistakes were forgetting to repeatedly prompt for an action if
something other than an 'l' or 'p' was entered and accidentally
printing the same line 20 times.

# set maximum number of lines
$max_num_lines = 20;
$line_count = $max_num_lines;

# until file is exhausted
while(<>) {

    print; 

    $line_count--;

    if ($line_count == 0) {

        do {

	  print("Action [l or p]: ");
          chomp($action = );

        } until (($action eq "p") || ($action eq "l"));

        if($action eq "p") {
            # print next 20 lines before prompting
            # for an action again
	    $line_count = $max_num_lines;
        } else {
            # only print one more line before prompting
            # for an action again
            $line_count = 1;
        }
    }
}


Louis Ziantz
3/26/1998