Perl Variables  «Prev  Next»

Perl Scalars in Context - Quiz

Each question is worth one point. Select the best answer for each question.
1. When is a scalar a number?
Please select the correct answer:
  A. When it has no alphabetic characters
  B. When it's used in a numeric context
  C. When it's used in any context

2. Given the line of code below, what is the type of the scalar variable $s? $s = "78"
Please select the correct answer:
  A. $s is a number
  B. $s is a string
  C. $s is a character

3. Which of the following is a valid Perl scalar data type?
Please select the correct answer:
  A. Array (@array)
  B. Hash (%hash)
  C. Scalar ($scalar)

4. Given my @letters = ('a', 'b', 'c'); what does my $count = @letters; assign to $count?
Please select the correct answer:
  A. 3, the number of elements in the array
  B. 'a', the first element of the array
  C. 'c', the last element of the array
  D. A reference to the array

5. What do '10' == '10.0' and '10' eq '10.0' evaluate to?
Please select the correct answer:
  A. Both are true
  B. Both are false
  C. == is true and eq is false
  D. == is false and eq is true

6. Running under use warnings, what does my $n = '3 blind mice' + 0; put in $n?
Please select the correct answer:
  A. 0, because the string does not begin with a complete number
  B. undef, because the conversion fails
  C. Nothing; the program dies with a fatal error
  D. 3, the numeric prefix read from the front of the string