IU Bloomington Evaluation Services and Testing

Indiana University
Bloomington Evaluation Services and Testing

QuizSite  Students
Quizzes · Tests · Evaluations · Surveys
Activity: Perl_Quiz
Student: dgerman (Adrian German)
Instructor: dgerman
Course: A348 Section: LECT
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:
(corrected Sep 24, 1999 credit goes to Roy and Charles).


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 = "There's a tomato in every automaton.";
$a =~ s/tomato/**/g;
print $a;

And the answer is:
(corrected Sep 24, 1999 credit goes to Charles Sugiarto)


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:
(corrected Sep 24, 1999 credit goes to Rudy, Charles & Roy).


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:


Click to submit your answers.   Help


This activity is available between these dates and times: 07.29.10:00-12.28.23:59
It can be submitted a total of 100 times.
If it is a scored activity, the highest non-zero score will be counted.


Screen: TAKE_QUIZ
Last updated: Thu Mar 8 13:40:07 2001
URL: https://www.indiana.edu/~best/cgi-bin/quizsite/students.pl
Comments: best@indiana.edu
Copyright 2000, BEST & The Trustees of Indiana University