Hashes in Perl - Quiz Explanation
The correct answers are indicated below, along with the text that explains the correct answers.
1.
What is the difference between a hash and an ordinary array?
Please select the best answer.
A.
Ordinary arrays cannot contain string values, while hashes can contain any type of scalar values
B.
Ordinary arrays use a numeric index, while hashes use a string index
C.
Ordinary arrays use a string index, while hashes use a numeric index
The correct answer is B.
A hash is an aggregate data structure that is indexed on a string-based key. A ordinary array uses a numeric index. Both ordinary arrays and hashes can contain any type of scalar values.
2.
In what order is a hash stored?
Please select the best answer.
A.
The order defined by the number of values in the hash
B.
The order defined by the internal hashing algorithm
C.
The order in which the values were stored in the hash
The correct answer is B.
The hash is stored internally in an order that is calculated to speed access.
This is almost never the order in which the values were stored.