Tutor Marked Assignment PL TMA-05
In a Nutshell - CIW Course Section 2 Part B
PL TMA-05 - CD Access Code: 13155
Q1. What would be displayed by the following Perl statements?
$mystr = "Mr. Fox and his foxy lady are here.";
if ($mystr =~ s#Fox#Cat#gi) {
print ("$mystr\n");
}
- a) Mr. Fox and his foxy lady are here.
- b) Mr. Cat and his caty lady are here.
- c) Mr. Cat and his Caty lady are here.
- d) Mr. Cat and his foxy lady are here.
Q2. Find the appropriate function for each metacharacter displayed.
- a) .
- b) ^
- c) $
- d) *
- e) +
- f) ?
- g) { }
- h) [ ]
- i) ( )
- 1) Denotes a range of occurrences for the element preceding it
- 2) Matches the preceding element one or more times
- 3) Matches the preceding element zero or one time
- 4) Used to group regular expressions
- 5) Matches any single character except newline when the /s modifier is being used
- 6) Matches the preceding element zero or more times
- 7) Creates a character class and matches any character where the metacharacter is applied
- 8) Matches at the end of a string or line if /m modifier is being used
- 9) Matches at the beginning of a string or line if /m modifier is being used
Q3. Which of these will /[aA]b?c$/ pattern match?
- a) Ac
- b) ab
- c) abc
- d) abbc
- e) [aA]b?c$
- f) aAbc
- g) Abcc
Q4. The pattern "/^[a-zA-Z]{1}[0-9]{1}[a-zA-Z]{1}$/;" is equivalent to pattern /^w{1}\d{1}\w{1}$/;
- a) True
- b) False
Q5. Match the Perl Assertions to their function.
- a) \b
- b) \B
- c) \A
- d) \Z
- e) \z
- f) \G
- 1) Matches at the beginning of a string
- 2) Matches at the end of a string only
- 3) Matches at the end of a string
- 4) Matches at word boundaries between \w and \W
- 5) Matches except at word boundaries
- 6) Matches where previous m//g left off
Q6. What would be displayed by the following Perl statements?
@fruits=("coconut", "banana", "orange",
"pineapple");
$mix = join(" ", @fruits);
@juice = split(/\s/, $mix);
print ("@juice\t");
- a) coconut,banana,orange,pineapple
- b) coconut
banana
orange
pineapple - c) coconut banana orange pineapple
- d) Tropical fruits juice
Q7. Which of these are "Okay names"?
print ("Enter firstname and lastname: ");
while (<STDIN>)
{
if (m#^[A-Z][a-z]*(\s[A-Z][a-z]*)+S#)
{
print ("Okay
names\n");
}
else
{
print ("Not good
names\n");
}
}
- a) Peter P Burton Clark
- b) bruce lee
- c) Lee mc Johnson
- d) Mary edwards
- e) Tracy Daniel Rupert
Q8. What will be assigned to the variable called 1 using pattern matching displayed below?
m/\w*.(.)\1\w*/
- a) Nothing
- b) The array of letters which occurs two times
- c) The array of words which occurs two times
- d) The first character which occurs more than once
- e) The last character which occurs more than once
- f) The first character which occurs two times
Q9. What would be displayed by the Perl statements shown below if you were to type the following list of words, each separated by a return keypress, on input? <STDIN> = dog, cat, dog, turtle, cat, turtle, end
print "Insert words to count: ";
$line = <STDIN>;
while ($line !~ m/^END$/i) {
while ($line =~ s/(\w+)(.*)/$2) {
$word = $1;
$wordHash{$word}++;
}
print "Insert words to count: ";
$line = <STDIN>;
}
print "\nWord counts:\n";
while (($word, $count) = each(%wordHash)) {
@wordArray[$1] = "$word\t\t$count";
$i++;
print ("@wordArray\n");
}
- a) Never ending loop
- b) dog 2
- c) dog 2
cat 2
turtle 2
end 1 - d) dog 2
cat 2
turtle 2
Q10. What does RPN stand for?
- a) Reverse Polish Notation
- b) Reserved Perl Notes
- c) Reserve Polish Notation
- d) Reserved Perl Notation

