1: | What are the two types of data you can use in Perl? |
A1:
| The two types of data you can use in Perl are scalar data, for individual things such as numbers and strings and list data, for collective things such as arrays. |
2: | What kinds of data make up scalar data? |
A2:
| Numbers, strings, and references. Full credit if you only said numbers and strings; we haven't talked about references yet. |
3: | What are the differences between double- and single-quoted strings? |
A3:
| There are two differences between single- and double-quoted strings:
Double-quoted strings can contain any number of special character escapes; single-quoted strings can only contain ' and \. Double-quoted strings will interpolate variables inside them (that is, replace the variables with their values).
|
4: | Which of the following are valid scalar variables?
$count
$11foo
$_placeholder
$back2thefuture
$long_variable_to_hold_important_value_for_later
|
A4:
| All the variables in that list except for $11foo are valid. $11foo is invalid because it starts with a number (Perl does have variables that start with numbers, but they're all reserved for use by Perl). |
5: | What's the difference between the = and == operators? |
A5:
| The = operator is the assignment operator, to assign a value to a variable. The == operator is for testing equality between numbers. |
6: | What's the difference between a statement and an expression? |
A6:
| A statement is a single operation in Perl. An expression is a statement that returns a value; you can often nest several expressions inside a single Perl statement. |
7: | What does this expression evaluate to: 4 + 5 / 3**2 * 6? |
A7:
| 7.33333333333333, give or take a 3 or two. |
8: | How do you round off numbers in Perl? |
A8:
| To round off numbers without printing them, use sprintf. To print numbers with less precision, use printf. |
9: | What are the values that Perl considers false? |
A9:
| Perl has three false values: 0, the empty string "", and the undefined value. |
10: | Why are there different operators for number and string comparisons? |
A10:
| Perl has different operators for numbers and strings because of its capability to auto-convert scalar values and the differences in handling both those values. |
11: | Define what a short-circuiting logical operator does. |
A11:
| Short-circuiting operators only evaluate their right-side operands when necessary. If the value of the left-side operator determines the overall value of the expression (for example, if the left side of a && operator is false), the expression will stop. |
12: | How is a pattern-matching test different from an equality test? |
A12:
| Equality tests return true if the scalars on both sides of the operator are exactly equal. Pattern matching tests result true of the scalar on the left side of the operator contains characters that match the pattern on the right side of the operator. |
13: | You have a pattern /ing/. Which of the following strings does this pattern match to?
'Singapore'
'viking'
'vainglorious'
'intermingle'
'Westinghouse'
'Ingmar'
|
A13:
| All the given strings match the pattern /ing/ except for the last one, 'Ingmar', which does not match because of the capital I. If the pattern /ing/ had an i at the end (/ing/i) then it would have matched the last pattern, as well. |