CS 460 -- A Perl of a Test


1) What does this program do?

    print "Status: 200 OK\nContent-type:  text/html\n\n";
    print "A Page about Cookies<br>\n";
    print "Set-Cookie: foo=bar; path=/students; expires Mon, 09-Dec-2002 13:46:00 GMT"


10) If someone sets the cookie as shown below.  Which CGI programs can access the cookie?  Which hosts and which cgi programs?
    "Set-Cookie: foo=bar; path=/students; expires Mon, 09-Dec-2008 13:46:00 GMT"



11) Write me perl code that drops the table "Hostess" from the database "Food".










100) Write me a perl program that counts the number of lines in the file "chip"?











101) What does this code do?  (Hint:  this might be tricky)
print foo(3);
    sub foo {
        $a = shift;
        if ($a == 1) { return 1; }
        else { $a * foo($a-1) }
    }

    

110) What is the minimum number of shift's the method must do to read the last argument to the call below?
    $object->method(1,2,3);


111) Which of the input strings below is matched by the regular expression /^ab*.*a$/
    aa aba abba abababa abababab


1000) Write me a function in perl that returns the sum of it's two arguments.










1001) What does this program print?
 #!/usr/bin/perl
    use IT;
    it = IT->new();
    $y = 2;
    it->twinky(3);
    it->dingdong(5)
package IT;
    sub new {
         my($class) = shift;
         bless { $x => 0 }, $class;
    }
    sub twinky {
          my($self) = shift;
          $y = 12;
          $self->{"x"} = 17;
    }
    sub dingdog {
          my($self) = shift;
          print $self->{"x"} . " = $y\n";
    }


1010) Write me a quick CGI program in Perl that prints the value of a cookie named "peanutbutter".











==========Choose an two of the following three========

Write me a program that prints every word with two vowels in a row in /usr/share/dict/words.  Be careful to count both upper and lower case letters.  'Y' counts as a vowel.  Two points. 



Write me a CGI script that lists who's logged in.  Hint:  The command to tell who's logged in is "w".


# Below is a program in Perl that asks for Doctors ages.  It uses a Max object to find the maximum of the doctor's age.  Write that object.  Show me the program working.  You can slightly modify the code below if you need to.
#!/usr/bin/perl -w
$a = Max->new();
print "Enter a doctor's age, or ^D to quit\n";
while($line = <STDIN>) {
       $a->newValue($line);
}
print "The max age is :";
print $a->getMax();
print " and that's old!\n";