CIW Course Revision Site


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");
}

Q2. Find the appropriate function for each metacharacter displayed.

 

Q3. Which of these will /[aA]b?c$/ pattern match?

Q4. The pattern "/^[a-zA-Z]{1}[0-9]{1}[a-zA-Z]{1}$/;" is equivalent to pattern /^w{1}\d{1}\w{1}$/;

Q5. Match the Perl Assertions to their function.

 

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");

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");
    }
}

Q8. What will be assigned to the variable called 1 using pattern matching displayed below?

m/\w*.(.)\1\w*/

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");
}

Q10. What does RPN stand for?

Design by Stephen

Certified Internet Webmaster

Page last Edited: 25 Nov 2011