These are your QuizSite Perl questions. To work with them you'd have to log into QuizSite where they are give to you as randomized selections. You can study them here though, and thus make sure you've covered all sample questions that were available before the midterm.


Question 1.
What is the output of the following Perl program:
#!/usr/bin/perl
@a = (1, 2, 3, 4); 
print $#a; 

The answer is:


Question 2.
Assume the following Perl program called one:
#!/usr/bin/perl
print $ARGV[1]; 
What is the output of the program when the program is called as follows:
./one my three arguments 

The program outputs:


Question 3.
What's the output of this simple Perl program:
#!/usr/bin/perl
$a = "abc 123 my oh my patterns 456 oh boy patter3ns"; 
if ($a =~ /(\d+)/) {
  print $1; 
} else { print "Nothing matches"; } 

And the answer is:


Question 4.
What's the output of this simple Perl program:
#!/usr/bin/perl
@a = ("one", "two", "three"); 
print join(':', @a); 

The answer is:


Question 5.
What's the output of this simple Perl program:
#!/usr/bin/perl
$a = ":4:3:2:1:"; 
@a = split(/:/, $a); 
print $#a; 

The answer is:


Question 6.
What's the output of this simple Perl program:
#!/usr/bin/perl
$a = "4:3:2:1"; 
@a = split(/:/, $a); 
print $#a; 

And the answer is:


Question 7.
What is the output of this simple Perl program:
#!/usr/bin/perl
$a = "abcde"; 
@a = split('', $a); 
print $#a; 

The answer is:


Question 8.
What's the output of this simple Perl program:
#!/usr/bin/perl
$a = "spippen:lbird:lbird:mjordan:lbird:mjordan"; 
@a = split(/:/, $a); 
foreach $a (@a) { $valuefor{$a} += 2; } 
print $valuefor{'mjordan'}; 

And the answer is:


Question 9.
What's the output for this simple Perl program:
#!/usr/bin/perl
$a = "abc123def456"; 
$a =~ s/\d+/:-)/;
print $a;  

And the answer is:


Question 10.
What's the output for this simple Perl program:
#!/usr/bin/perl
$a = "abc123def456"; 
$a =~ s/\d*/:-)/; 
print $a; 

And the answer is:


Question 11.
What's the output for this simple Perl program:
#!/usr/bin/perl
$a = "123_abc_456"; 
if ($a =~ /(\w+)/) {
  print $1; 
} else { print "No match"; } 

The answer is:


Question 12.
What's the output for this simple Perl program:
#!/usr/bin/perl
%myHash = ('Jordan' => 'awesome', 
           'Bird'   => 'outstanding', 
           'Kukoc'  => 'very good'); 
foreach $key (keys %myHash) {
  print $key, ", "; 
} 

The answer is:


Question 13.
What's the output for this simple Perl program:
#!/usr/bin/perl
%myHash = ('Jordan' => 'awesome', 
           'Bird'   => 'outstanding', 
           'Kukoc'  => 'very good');
foreach $key (sort (keys %myHash)) {
  print $key, ", "; 
} 

The answer is:


Question 14.
What's the output for this simple Perl program:
#!/usr/bin/perl
@a = (4, 3, 2, 1); 
print $a[$#a]; 

The answer is:


Question 15.
What's the output for this simple Perl program:
#!/usr/bin/perl
$i = 0; $j = 1; 
if ($i = 2) { print $i; }
else { print $j; } 

The answer is:


Question 16.
What's the output for this simple Perl program:
#!/usr/bin/perl
$i = 0; $j = 1; 
if ($i == 2) { print $i; }
else { print $j; } 

The answer is:


Question 17.
What's the output for this simple Perl program:
#!/usr/bin/perl
$a = "bloomington"; 
$a =~ s/loo/lue/; 
print $a; 

The answer is:


Question 18.
What's the output for this simple Perl program:
#!/usr/bin/perl
$a = "1:2:3:4"; 
@a = split(/:/, $a); 
foreach $a (@a) { $var += $a; } 
print $var; 

And the answer is:


Question 19.
What's the output for this simple Perl program:
#!/usr/bin/perl
$a = 1; 
print $a; 
$a = $a + "something"; 
print $a; 

And the answer is:


Question 20.
What's the output for this simple program:
#!/usr/bin/perl
$a = "automaton";
$a =~ s/to//g; 
print $a; 

And the answer is:


Question 21.
What does the following program (called one)
#!/usr/bin/perl
print join(':', @ARGV); 
produce when called as follows:
./one a b c d

And the answer is:


Question 22.
What's the output of this small Perl program:
#!/usr/bin/perl
$a = "section=9014&language=perl&course=a348"; 
@a = split(/&/, $a); 
foreach $a (@a) {
  ($u, $v) = split(/=/, $a); 
  $hash{$u} = $v; 
}
print chop($hash{'section'}); 

And the answer is:


Question 23.
What's the output of this small Perl program:
#!/usr/bin/perl
$a = "this is my string"; 
print substr($a, 0, 7) . " good "; 

And the answer is:


Question 24.
What's the output of this small Perl program:
#!/usr/bin/perl
$a = "this is a string"; 
$a =~ s/(\W)/($1)/;
print $a; 

And the answer is:


Question 25.
What's the output of this small Perl program:
#!/usr/bin/perl
$a = "one"; $b = "two";
if ($a == $b) { print $a + $b; }
elsif ($a < $b) { print $b; }
else { print $a; } 

And the answer is:


Question 26.
What's the output of this small Perl program:
#!/usr/bin/perl
$a = "This space for rEnt"; 
$a =~ s/[aeiou]//g; 
print $a; 

And the answer is:


Question 27.
What's the output of this small Perl program:
#!/usr/bin/perl
$a = "This is my song for the asking";
@a = split(/i/, $a); 
print $a[0]; 

And the answer is:


Question 28.
What's the output of this small Perl program:
#!/usr/bin/perl
$a = "1::2:3:4"; 
$a =~ s/:+/:/g; 
@a = split(/:/, $a); 
print $a[1]; 

The answer is:


QuizSite was designed and implemented at The Bureau of Evaluative Studies & Testing - Indiana University, Bloomington, Indiana,
with the generous contribution of Bloomington faculty


Screen last updated: 15 August 1997
URL: https://carrot.franklin.indiana.edu/cgi-bin/student/197/quizsite
Comments: best@indiana.edu
Copyright 1996, BEST & The Trustees of Indiana University