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?
- a) Key
- b) Index
- c) Value
- d) Token
Q2. Hash names are not case sensitive.
- a) True
- b) False
Q3. In relation to hashes, the => operator has the same function as what?
- a) % (percent)
- b) . (full stop)
- c) & (ampersand)
- d) , (comma)
Q4. A significant difference between hashes and arrays is that hash elements are ________.
- a) strings
- b) unordered
- c) modifiable
- d) ordered
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.
- a) iselement, remove
- b) iselement, delete
- c) exists, remove
- d) exists, delete
Q6. Which of the following is a problem with the reverse function?
- a) It can be performed only once on a single hash.
- b) It also reverses the order with which key/value pairs held within a hash.
- c) If a key exists multiple times within a hash, all but one of the key/value pairs will be lost.
- d) If a value exists multiple times within a hash, all but one of the key/value pairs will be lost.
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.
- a) True
- b) False
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);
- a) 7seven9nine2two8eight4four1one0zero
- b) 4four1one9nine2two8eight0zero
- c) four4one1two2eight8seven7zero0nine9
- d) 0zero1one2two4four7seven8eight9nine
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});
}
}
- a) zerothreesixnine
- b) onetwofourfiveseveneight
- c) ninesixthreezero
- d) sixninezerothree
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);
- a) 365192
- b) 0563921
- c) threesizfiveoneninetwo
- d) zerofivesixthreeninetwoone
