CIT 597 Quiz 5: SAX and Perl
Fall 2008, David Matuszek Name_________________________________________
  1. (10 points) What two advantages does SAX have over DOM?

    Faster, uses less memory.


  2. (10 points) SAX calls your characters method with what three pieces of information?

    A character array, and the start position and length of a string in that array.


  3. (10 points) Under what circumstances does SAX ignore whitespace?

    When it is validating (has a DTD) and PCDATA is not allow in that location.


  4. (60 points) Write a regular expression that will match each of the following (and nothing else!):

    1. A sequence of one or more digits. (Hint: \d matches one digit.)
      \d+

    2. A hyphenated ten-digit phone number, such as 215-898-8122.
      \d\d\d-\d\d\d-\d\d\d\d   or   \d{3}-\d{3}-\d{4}

    3. A 16-digit credit card number, such as 1234 5678 9012 3456, where the space between each four-digit group is optional. (Use an underscore, _, to represent a space.)
      \d\d\d\d_?\d\d\d\d_?\d\d\d\d_?\d\d\d\d  or  (\d\d\d\d_?){3}\d\d\d\d

    4. A complete word that does not contain one of the five vowels (aeiou).
      \b[bcdfghjklmnpqrstvwxyz]+\b 
       \b[^aeiou]+\b  does not work (but is worth partial credit)
    5. The two characters that start a C (C++, Java) comment, either // or /*.
      //|/\*  or  /(/|\*)

    6. The complete string being tested, if and only if it contains a double letter pair (such as oo or TT). You can assume the string does not contain newlines.
      ([a-zA-Z])\1

  5. (10 points) Write a Perl statement to terminate the program with an error message if the variable $fileName contains a space.

    if ($fileName =~ /_/) die("File name contains a space.");  // using _ to mean a space