How to Identify a Good Perl Programmer, Answer Key
Monday, 17 January 2011—subject to ongoing, unnanounced updates
- previous » String trim, snip, collapse in Perl
Modern Perl at Powell’s, Modern Perl at Barnes and Noble, Modern Perl at Amazon.com, or download Modern Perl for free and then recommend it to your friends, write a great review, or otherwise spread the word.
Re: How to Identify a Good Perl Programmer
These aren’t authoritative. Just felt like trying my hand since chromatic said a good Perl 5 programmer should know 80%. Woo-woo.
- What do variable sigils indicate in Perl 5?
- The underlying content. % ➙ hash, @ ➙ array, $ ➙ scalar. The trick perhaps being that a scalar variable can hold just about anything as a reference; from an object to a regular expression.
- What's the difference between accessing an array element with
$items[$index]and@items[$index]?- The first is right. :) The second is a single item array slice and is deprecated.
- What's the difference between
==andeq?- Numeric vs stringwise equality comparison in that order. The stringwise operators are spelled with letters; e.g.,
lt,ge,cmp.
- Numeric vs stringwise equality comparison in that order. The stringwise operators are spelled with letters; e.g.,
- What do you get if you evaluate a hash in list context?
- All its elements—in key, value pairs—in whatever order perl thinks they are best kept.
- How do you look up keywords in the Perl documentation?
perldoc -f pack… or perldoc.com.
- What is the difference between a function and a method in Perl 5?
- Well… there isn’t any exactly. A method expects, or needs, the first argument to be a class or object. The calling class or object is passed as the first argument which looks like:
Class::Name->method_name($arg)or$object->method_name($arg). This does make the following the same in some cases:method_name($object, $arg).
- Well… there isn’t any exactly. A method expects, or needs, the first argument to be a class or object. The calling class or object is passed as the first argument which looks like:
- When does Perl 5 reclaim the memory used by a variable?
- When it and all of its referents go out of scope.
- How do you ensure that the default scope of a variable is lexical?
- Declare it with
my.
- Declare it with
- How do you load and import symbols from a Perl 5 module?
- use Module::Name ( $optional, $args ) or
require+import. - How can you influence the list of directories from which
perlattempts to load modules?- By altering
@INC. There are quite a few ways to do that. Thelibpragma andPERL5LIBenvironment variables being the two most straightforward; well, that and execution directory.
- By altering
- How do you look up error messages in the Perl 5 documentation? (Award bonus points for knowing how to enable explanations of all error messages encountered.)
- Um… I’m not sure.
perldoc -q errorpoints toperlfaq8. You canuse diagnosticsto make your warnings and errors much more verbose.
- Um… I’m not sure.
- What happens when you pass an array into a function?
- It’s available in
@_.
- It’s available in
- How do you pass one or more distinct arrays into a function?
- Array references like
function(\@one,\@two)or I think you could do it by using a prototype, which is almost always a bad idea.
- Array references like
- What is the difference, on the caller side, between
return;andreturn undef;?- The first unrolls by context to an
undefscalar or an empty list (). The second, always toundef.
- The first unrolls by context to an
- Where do tests go in a standard CPAN distribution?
t/.
- How do you run tests in a standard CPAN distribution?
prove -l t/(and I like the-vas well).
- What command do you use to install new distributions from the CPAN?
cpanm, believe it.
- Why would you use the three-argument form of the
openbuiltin?- Security, robustness, and quoting.
- How do you detect (and report) errors from system calls such as
open? (Award bonus points for knowing how to enable automatic detection and reporting of errors.)- They return true on success.
use autodieto turn the failures into fatals.
- They return true on success.
- How do you throw an exception in Perl 5?
die, wellcroakorconfessif you please.
- How do you catch an exception in Perl 5?
eval {}or maybeuse Try::Tinyis the right choice at this point.
- What is the difference between reading a file with
forand withwhile?- All at once or one record at a time.
- How do you handle parameters within a method or function in Perl 5?
- Uh… what? You take them or copy them out of
@_.
- Uh… what? You take them or copy them out of
- What do parentheses around the variable name in
my ($value) = @_;mean, and what would happen if you removed them?- They keep the list context. Without them you get the size of
@_.
- They keep the list context. Without them you get the size of
- Is
newa builtin function/keyword?- No.
- How do you read the documentation of a core library? A CPAN module?
perldoc Module::Name.
- How do you access only the values of a Perl 5 hash?
values %hash.
So… Did I get the part?