



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




REGULAR EXPRESSIONS (15%)
leading or trailing whitespace. For example: (3pts) /* This is a comment that happens to span multiple lines */
$string = "aaaab"; if ($string =~ /(a*)a(a|b)/){ print "$1\n"; }
yourself with matching 'special variables' like $"). Recall that Perl variables must start with a letter or underscore, but the remaining characters may be letters, underscores, or numbers. (3 pts)
while ($in !~ /^quit/i){ #do stuff…. print "Enter an input, or the word "quit" to end\n"; }
readability of the code? (3 pts) $pattern =~ m/ #start the regexp (\d*) #search for 0 or more digits, and save them \s+ #at least one whitespace \1 #the same digit pattern ([A-Za-z]) #search and save a single letter /; #end the regular expression
CLASSES/MODULES (15%)
set Name to the null string, and Age to 0. (10 pts)
method on that member: (5 pts) package MyClass.pm; sub create { my $obj = {foo => 20, bar => -20}; bless $obj, MyClass; return $obj; } sub change { $obj = shift @_; $obj{foo}++; $obj{bar}--; }
RANDOM BITS OF PERL (20%)
program man (without the brackets). If it is a command, run the command and display the output of the command. If it is not, print a message saying it's not a command. Hint: man returns the message No manual entry for . if it cannot find an entry, and a description of the command if it can. (5 pts) Here are two sample run-throughs of your program (user input is bold): Enter a command: ls output of ls: file1.txt program.pl page.html Enter a command: blargh! Sorry, blargh! is not a command.
@numbers = (1..10); @num2 = map {$_ * 4} @numbers; @num3 = grep {$_ % 3 == 0} @num2; print "The contents of @num3 are: @num3\n";
$message = "Hello World"; $value = 42; print qq(I was told, "Give him the message: $message".\n); print q("What's the answer"? Well, $value, of course!\n);
and dump.cgi simply prints the header, starting HTML, the return value of Dump(), and ending HTML, show the output of dump.cgi: (5 pts)
Lally Amos Eaton DCC
radio buttons are marked "RPI" and "CS Dept". The user of your script enters his RCS user Id in the text box, and chooses one of the two radios. When the user presses the submit button, your script displays a page saying which radio was selected, and create an HTML link to that user's webpage, on either the RPI or CS Dept system. For example, if I enter my user id and select CS Dept, your script generates: You have chosen the CS Dept. Your home page is here If I select RPI, the link instead goes to www.rpi.edu/~lallip If the user does not enter a UserId, you should display an error message and nothing else. (10 pts) Why not change the world x x Lally DCC Amos Eaton GoThere