CIT 042 Index > Midterm 2 Review

Midterm 2 Review

These are the kinds of topics and questions you can expect to see on the midterm. It’s open book, open notes, open mind, but not open computer or open neighbor.

  1. Given this string: The rain in Spain falls mainly in the plain. and this pattern: /\w+([aeiou]{2})\w\B/, which part of the string will the entire pattern match, and what will be stored in $1?

  2. What is the output of this code?

    $str = "Numbers: 5, 12, 17";
    $str =~ s/(\d+), (\d+), (\d+)/$3 = $1 + $2/;
    print $str;
  3. Write a pattern that will match a day of a month (i.e., any of the numbers 1 through 31), and will not match anything that isn’t in that range.

  4. Given the string =across= =the= =universe=, what will be matched by this pattern: /=t.*=/ and this one: =t.*?= (In other words, know the difference between greedy and non-greedy matching.)

  5. Know how to open a file, read from it, and then close it.

  6. Know what the open( ) function returns if you try to open a file that does not exist or if the open fails for some reason.

  7. Know how to open a file for writing and how to write text to it.

  8. Know about the @ARGV array.

  9. Know about the “file test” operators like -e and -d, etc. (see page 199)

  10. Know how to use string operators like index, rindex, and substr.

  11. Know how to create and remove directories.

  12. Know how to execute system commands from a Perl program.