Tutor Marked Assignment PL TMA-03
In a Nutshell - CIW Course Section 2 Part B
PL TMA-03 - CD Access Code: 7866
Q1. When using the foreach statement, the control variable is written as what?
- a) $_
- b) @_
- c) &_
- d) #_
Q2. Given the following array declaration, which statement would display the last element from the array?
@seasons = ("Spring", "Summer", "Autumn", "Winter");
- a) print (@seasons[4]);
- b) print (@seasons[3]);
- c) print ($seasons[4]);
- d) print ($seasons[3]);
Q3. Perl arrays can contain string or numerical values, but not both.
- a) True
- b) False
Q4. What would be the output from the following Perl coding?
@array1 =!19..14);
@array2 = (9, @array1, 14, 15);
print ("array2");
- a) 9 10 11 12 13 14 14 15
- b) 9 10 11 12 13 14 15
- c) 9 10 14 14 15
- d) 9 14 15
Q5. What would be the output from the following Perl coding?
@array1 = (10..13);
@array2 = @array1;
$array1[0] = 9;
print ("@array2");
- a) 10 13
- b) 9 11 12 13
- c) 9 10 11 12 13
- d) 10 11 12 13
Q6. What would be the output from the following Perl coding?
@array = "3, 6, 5, 4, 1);
@array = sort {$a <=> $b} @array;
$array[0] = 2;
print ("@array");
- a) 2 6 5 4 1
- b) 2 5 4 3 1
- c) 1 3 4 5 6
- d) 2 3 4 5 6
Q7. What would be the output from the following Perl coding?
@array = (3, 6, 5, 4, 1);
$array[$#array] = 7;
@array = sort {$b <=> $a} @array;
print ("@array");
- a) 3 4 5 6 7
- b) 1 3 4 5 6
- c) 7 6 5 4 3
- d) 6 5 4 3 1
Q8. What would be the output from the following Perl coding?
@array = {"Tom", "Dick", "Harry");
sort {$b cmp $a} @array;
print ("@array");
- a) Tom Dick Harry
- b) Dick Harry Tom
- c) Tom Harry Dick
- d) Harry Dick Tom
Q9. What would be the output from the following Perl coding?
@array = (10, 7, 3, 8, 13, 4, 2);
push(@array, shift(@array));
@array = sort {$b <=> $a} @array;
print ("@array");
- a) 2 3 4 7 8 10 13
- b) 2 3 4 7 8 13
- c) 13 10 8 7 4 3 2
- d) 13 8 7 4 3 2
Q10. What would be the output from the following Perl coding?
@array = (10 3..8, 13, 2);
shift(@array);
unshift(@array, 9);
pop(@array);
print ("$#array");
- a) 9
- b) 8
- c) 7
- d) 6

