Home
51.
What kinds of data make up scalar data?

Numbers, strings, and references. Full credit if you only said numbers and strings; we haven’t talked about references yet.

52.
What are the differences between double- and single-quoted strings?

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).

53.
Which of the following are valid scalar variables?
$count
$11foo
$_placeholder
$back2thefuture
$long_variable_to_hold_important_value_for_later

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).

54.
What's the difference between the = and == operators?

The = operator is the assignment operator, to assign a value to a variable. The == operator is for testing equality between numbers.

55.
What's the difference between a statement and an expression?

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.

56.
What's the die function used for? Why should you bother using it with open?

The die function exits the script gracefully with a (supposedly) helpful error message. It's most commonly used in conjunction with open because if something so unusual happened that the file couldn’t be opened, generally you don't want your script to continue running. Good programming practice says always check your return values for open and call die if it didn’t work.

57.
How do you read input from a file handle? Describe how input behaves in a scalar context, in a scalar context inside a while loop test, and in a list context.

Read input from a file handle using the input operator <> and the name of the file handle. In scalar context, the input operator reads one line at a time. Inside a while loop, it assigns each line to the $_ variable. In a list context, all the input to end of file is read.

58.
How do you send output to a file handle?

Send output to a file handle using the print function and the name of the file handle. Note that there is no comma between the file handle and the thing to print.

59.
What is @ARGV used for? What does it contain?

The @ARGV array variable stores all the arguments and switches the script was called with.

60.
What's the difference between getopt and getopts?

The getopt function defines switches with values, and can accept any other options. The getopts declares the possible options for the script and if they have values or not. The other difference is that getopts returns a false value if there were errors processing the command-line switches; getopt doesn’t return any useful value.