Perl References Quiz - Explanation

The correct answers are indicated below, along with text that explains the correct answers.
1. A Perl reference is:
Please select the best answer.
  A. Limited to two-dimensional data
  B. the contents of a variable
  C. a scalar variable that points to another object
  The correct answer is C.
A Perl reference is a scalar variable that points to another object. A is incorrect because two-dimensional data refers to Perl's data types, rather than its reference. B is incorrect because a reference is not the contents of a variable. It is a pointer to those contents.


2. A dereference is:
Please select the best answer.
  A. A reference to an object in Perl.
  B. An object being accessed via a reference.
  C. A scalar variable being accessed via an object.
  The correct answer is B.
A dereference is an object being accessed via a reference.
Answer A refers to a reference that contains addresses of other variables and types of variables to which they point.
C is incorrect because a dereference refers to an object that is being accessed via a reference, not referenced by an object.

3. An anonymous object is:
Please select the best answer.
  A. an element of the dereferenced array
  B. an object without a name
  C. a special arrow operator
  The correct answer is B.
An anonymous object is an object without a name that can be accessed only through references.

4. Refer to this code fragment to answer the following questions:
$var1 = "George";
$var2 = \$var1;
$var3 = $var2;
$var4 = $$var2;
$var5 = $$var3;
Which variables are references?
Please select the best answer.
  A. $var2 and $var3
  B. $var1
  C. $var5 and $var1
  The correct answer is A.
The syntax, \$var1 is a reference to $var1. The assignment $var2 = \$var1; assigns that reference to $var2. And $var3 is simply a copy of $var2.

5. What are they references to?
Please select the best answer.
  A. $var1
  B. George
  C. used to aggregate data into smaller dimensions
  The correct answer is A.
The syntax, \$var1 is a reference to $var1. The assignment $var2 = \$var1; assigns that reference to $var2.
And $var3 is simply a copy of $var2.
C is incorrect because Perl reference allows you to aggregate data into larger dimensions, not smaller ones.

6. What is the content of $var4?
Please select the best answer.
  A. \$var1
  B. "George"
  C. $var2
  The correct answer is B.
The syntax, $$var2 is a dereference of $var2, which returns the content of the referenced scalar.

7. What is the content of $var5?
Please select the best answer.
  A. $var2
  B. \$var1
  C. "George"
  The correct answer is C.
The syntax, $$var3 is a dereference of $var3, which returns the content of the referenced scalar.