CS 290W Exam 2 Key
Fall 1999
Answers are in RED. Questions 12 and 40 were not graded (discarded).
JavaScript
(a) true
(b) false
The function:
saySomething(message) {
alert(message)
}
The call to the function:
<INPUT TYPE=BUTTON VALUE="Hello" onClick="return(saySomething('HI'))">
(a) true
(b) false
(a) true
(b) false
(a) true
(b) false
(a) Anchor
(b) INPUT
(c) both (a) and (b)
(d) neither (a) nor (b)
Perl
$twk = tr/udin/1234/;
What is $twk after the tr statement?
(a) "p1r21e 143vers3ty"
(b) "p1r2e 1vers3ty"
(c) "purdue university"
(d) 7
(a) change all occurences of 0-9 to d
(b) delete all digits 0-9
(c) change all occurences of 0-9 to a blank character
(d) count the number of digits 0-9, but leave the string unchanged
What should be in the Perl program somewhere?
(a) sub Rent {...}
(b) sub &fRent {...}
(c) sub fRent {...}
(d) sub &Rent {...}
(a) func
(b) sub
(c) subrtn
(d) &
(a) true
(b) false
$sub = "aha";
$idx = index($pres, $sub);
What is $idx?
(a) -1
(b) 3
(c) 4
(d) 5
$new = substr($old, 3, 9);
What is $sNew?
(a) "ibacter"
(b) "tibacte"
(c) "ibacte"
(d) "bacte"
(a) if ($iReb >= 100)
(b) if ($iReb < 100)
(c) unless ($iReb > 100)
(d) unless ($iReb <= 100)
$smthg = @lst;
What is now in $smthg?
(a) ('p', 'm', 'j', 'd')
(b) 'd'
(c) 3
(d) 4
(a) true
(b) false
(a) Perl programs cannot have any functions.
(b) Perl programs are used for cgi applications.
(c) Perl is NOT an object-oriented programming language.
(d) It is interpreted at run time.
(a) #! /usr/perl/bin/perlin
(b) #! /usr/perl/bin
(c) #! /perlin
(d) #! /usr/local/bin/perl
(a) chmod a+rx search.cgi
(b) chmod a+rw search.cgi
(c) chmod a+r search.cgi
(d) chmod u+rx search.cgi
(a) blank(s)
(b) newline(s) \n
(c) .
(d) digit(s) (0-9)
(a) ($frst eq $secnd)
(b) ($frst = $secnd)
(c) ($frst == $secnd)
(d) ($frst.$secnd)
(e) none of the above
(a) $anArray
(b) @anArray
(c) $anArray[$iWhich]
(d) none of the above
(a) findauthor.txt
(b) findauthor.pl
(c) findauthor.class
(d) findauthor.perl
(a) Must be in a cgi-bin directory.
(b) Must have the suffix .pl.
(c) Must have the suffix .cgi.
(d) Must be in a cgi-bin directory and have the suffix .cgi.
(a) $sBase+$sAssignment
(b) $sBase,$sAssignment
(c) $sBase.$sAssignment
(d) $sBase cat $sAssignment
chop($sReason);
What will now be in $sReason?
(a) "My dog ate it"
(b) "My dog ate i"
(c) "My dog ate"
(d) "dog ate it"
(a) if ($iNum < 100) {$iFlag=0;} elsif ($iNum < 500) {$iFlag=1;}
(b) if ($iNum < 100) {$iFlag=0;} else {$iFlag=1;}
(c) if ($iNum < 100) {$iFlag=0;} elsif ($iNum >= 100) {$iFlag=1;}
(d) if ($iNum < 100) {$iFlag=0;} elsif ($iNum < 500) {$iFlag=1;} else {$iFlag=2;}
print "My favorite butter is $sButter. Do you like it? \n";
What will be printed?
(a) My favorite butter is $sButter. Do you like it?
(b) My favorite butter is Land-o-Lakes. Do you like it?
(c) My favorite butter is $sButter. Do you like it? \n
(d) none of the above
print 'My favorite butter is $sButter. Do you like it? \n';
What will be printed?
(a) My favorite butter is $sButter. Do you like it?
(b) My favorite butter is Land-o-Lakes. Do you like it?
(c) My favorite butter is $sButter. Do you like it? \n
(d) none of the above
print "My favorite butter is \$sButter. Do you like it? \\n";
What will be printed?
(a) My favorite butter is $sButter. Do you like it?
(b) My favorite butter is Land-o-Lakes. Do you like it?
(c) My favorite butter is $sButter. Do you like it? \n
(d) none of the above
Which of the following prints the single number 146?
(a) print "$A[2] \n";
(b) print "$A \n";
(c) print "@A \n";
(d) none of the above
$B = @A;
What is $B?
(a) 5
(b) 6
(c) (200, 255, 146, 307, 199, 312)
(d) 200
Which of the following loops uses each of the @myArray values in consecutive order?
(a) foreach @myArray ($wide) {...}
(b) foreach $wide (@myArray) {...}
(c) useach $wide (@myArray) {...}
(d) for $wide (@myArray) {...}
(a) Put the value on the last line of the function followed by a semi-colon
(b) return (value);
(c) Put it into $_
(d) both (a) and (b)
Which of the following will evaluate to true?
(a) if ($sEmailAddress =~ m/BIO/i)
(b) if ($sEmailAddress =~ m/biological/)
(c) if ($sEmailAddress == m/BIO/)
(d) if ($sEmailAddress =~ m/BIO/)
36. Which of the following writes information into the file in the previous question?
(a) print ">srchterms.txt $sSrchtext $iEndtag \n";
(b) print "$sSrchtext $iEndtag \n";
(c) print srchterms.txt "$sSrchtext $iEndtag \n";
(d) print SRCHFOR "$sSrchtext $iEndtag \n";
37. Unix files are complicated in that they do not have to reside on disk. They can be any stream of ordered bytes that a program can access.
(a) true
(b) false
38. Perl mainly deals with binary files.
(a) true
(b) false
39. In Perl programs, it is convention to use all lower case letters with file handles.
(a) true
(b) false
40. The Perl open() function does two things: 1) opens a file, and 2) returns a boolean
(a) true
(b) false
41. The die function does two things: 1) prints a message, and 2) returns execution to the main program
(a) true
(b) false
42. File input operator: <FiLeNaMe>
(a) returns a line from named text file, including the newline character
(b) returns a line from named text file, excluding the newline character
(c) only opens the file for reading and writing
(d) creates a file
43. Which of the following is true?
(a) $_ is a default variable that gets assigned if you do not specify a scalar
(b) @_ is a default variable that gets assigned if you do not specify a scalar
(c) the m// operator searches the default variable
(d) both (b) and (c)
(e) both (a) and (c)
44. Consider the following expression: @myFile = <A>;
(a) this reads a whole file into an array
(b) this is an illegal assignment
(c) this writes a whole array to a file
(d) is not an assignment at all, but a comparison expression
45. Using the select function is encouraged, since it allows you to have several files open at once, thereby cutting down on the number of lines of code
(a) true
(b) false
46. $_ = "Babs the cat decided to STAY at home";
$iMatched = s/..a.../fred/gi;
(a) $_ is now "Babs thefredecided to fredt home" and $iMatched is now 2
(b) $_ is now "fredthefredecided to fredt home" and $iMatched is now 3
(c) $iMatched is now "fredthefredecided to fredt home"
(d) none of the above
47. How are parameters passed to Perl functions?
(a) as scalars in the default variable: $_
(b) in the parameter array @_
(c) in the parameter array @$_
(d) the same as in any other language we've seen so far
48. What is true about variables in Perl?
(a) all Perl variables are global, unless you declare them local by using the my function
(b) all Perl variables are local, unless you use the global function
(c) Perl variables are considered local if defined in a function, just like in any other language
we've see so far, and global if declared outside the function
(d) Perl cannot have local variables
49. You can print an entire list (array) with this statement: print @someList;
(a) true
(b) false
50. Which environment variable can tell you how your data is being sent to the server?
(a) HTTP_REFERER
(b) HTTP_USER_AGENT
(c) REQUEST_METHOD
(d) SEND_REQUEST
(e) none of the above