Perl Variables  «Prev  Next»

Scalar Type and Variable - Quiz

Each question is worth one point. Select the best answer for each question.
1. Which of the following is a correct scalar variable name?
Please select the correct answer:
  A. firstName
  B. $1firstName
  C. $firstName

2. What is the difference between a scalar value and a scalar variable?
Please select the correct answer:
  A. A scalar value has a name associated with it
  B. A scalar variable has a name associated with it
  C. A scalar variable can hold several values at once, while a value cannot

3. Given my $name = 'Perl'; what do "Hello $name" and 'Hello $name' produce?
Please select the correct answer:
  A. Hello Perl and Hello $name
  B. Hello Perl from both
  C. Hello $name and Hello Perl
  D. Hello Perl and a syntax error

4. A scalar has been declared but never assigned, as in my $count; What does it contain?
Please select the correct answer:
  A. The number 0
  B. The empty string
  C. undef, which is neither 0 nor the empty string
  D. Nothing; using it is a fatal error

5. What does $id hold after my $id = 'aa'; $id++;?
Please select the correct answer:
  A. ab
  B. 1, because the string converts to a number first
  C. aa1
  D. undef; the increment fails on a non-numeric string

6. Which of these is not a valid way to write a number in Perl?
Please select the correct answer:
  A. 1_000_000
  B. '1_000_000'
  C. 0xff
  D. 1.5e3