CIW Course Revision Site

Tutor Marked Assignment PL TMA-04

In a Nutshell - CIW Course Section 2 Part B

PL TMA-04 - CD Access Code: 10506

Q1. Hashes contain elements that can be accessed using a scalar variable called a what?

Q2. Hash names are not case sensitive.

Q3. In relation to hashes, the => operator has the same function as what?

Q4. A significant difference between hashes and arrays is that hash elements are ________.

Q5. You can use the ________ function to verify that an element is present within a hash, and the ________ function to remove elements from a hash.

Q6. Which of the following is a problem with the reverse function?

Q7. The keys function generates a list of the keys associated with a hash. Unlike the hash, however, the keys generated by the keys function are ordered.

Q8. Which of the following alternatives could be the output from the following Perl coding?

#!c:\perl\bin\perl.exe

%digits = ("zero" => 0, "one" => 1, "two => 2,
                   "three" => 3, "four" => 4, "five" => 5,
                   "six" => 6, "seven" => 7, "eight" => 8,
                   "nine" => 9);

%digits = reverse(%digits);
for ($i = 3; $i < 7; $i++)
{
    if ($i != 4)
    {
        delete($digits{$i});
    }
}
print (%digits);

Q9. Which of the following alternatives could be the output from the following Perl coding?

#!c:\perl\bin\perl.exe

%digits = ("zero" => 0, "one" => 1, "two => 2,
                   "three" => 3, "four" => 4, "five" => 5,
                   "six" => 6, "seven" => 7, "eight" => 8,
                   "nine" => 9);

%digits = reverse(%digits);
for ($i = 0; $i <= 9; $i++)
{
    if ($i % 3 == 0)
    {
        print($digits{$i});
    }
}

Q10. Which of the following alternatives could be the output from the following Perl coding?

#!c:\perl\bin\perl.exe

%digits = ("zero" => 0, "one" => 1, "two => 2,
                   "three" => 3, "four" => 4, "five" => 5,
                   "six" => 6, "seven" => 7, "eight" => 8,
                   "nine" => 9);

while (($key, $value) = each(%digits))
{
    if ($value % 4 == 0 || $key eq "seven")
    {
        delete($digits{$key});
    }
}
@hashvals = values(%digits);
print (@hashvals);

Design by Stephen

Certified Internet Webmaster

Page last Edited: 25 Nov 2011