Home > Articles > Web Development > Perl

  • Print
  • + Share This
This chapter is from the book

Workshop

The workshop provides quiz questions to help you solidify your understanding of the material covered and exercises to give you experience in using what you've learned. Try and understand the quiz and exercise answers before you go on to tomorrow's lesson.

Quiz

  1. What's the difference between the postfix increment operator ($x++) and the prefix increment operator (++$x)?

  2. What does operator precedence determine? How about associativity?

  3. What is the difference between the following patterns?

  4. /d/
    /\d/
    /\D/
    /d\d/ 
  5. You have the pattern /\d\d\D/. Which of the following strings does this pattern match to?
    '456'
    'd55'
    '55+'
    '4aa'
    '4b'
  6. What is a file handle? Why do you need one?

  7. Define standard input and output. What are they used for?

  8. What does the chomp function do?

  9. What are the differences between print, printf, and sprintf? When would you use each one?

  10. What do the following operators do?

    1. .
      **
      ne
      ||
      *=

Exercises

  1. Write a program that accepts any number of lines of any kind of input, ending with a Return or Enter (similarly to how the stats.pl program works). Return the number of lines that were entered.

  2. BUG BUSTER: What's wrong with this bit of code?

while () {
 print 'Enter a name: ';
 chomp ($input = <INPUT>);
 if ($input ne '') {
 $names++;
}
 else { last; }
}
  1. Write a program that accepts input as multiple words on different lines, and combines those words into a single string.

  2. Write a program that takes a string and then centers it on the screen (assume an 80-character line, and that the string is less than 80 characters). Hint: the length function will give you the length in characters of a string.

  3. Modify the Fahrenheit to Celsius converter program from yesterday to make sure that the input is a valid digit. If the user enters something invalid, loop until the input is valid. Watch out for negative numbers!

  • + Share This
  • 🔖 Save To Your Account