See On Interviewing and Interview Questions for how I have gone about interviewing over the years.
Further to that, I've dug out some old Perl interview questions
I used to assess candidates who said they "knew" Perl (to keep them honest).
That is, these questions are not difficult for a Perl expert.
- What is the CPAN?
- What does use strict; mean?
- What is the difference between $x eq $y and $x == $y?
- What is the definition of "false" in Perl?
- Generally, when should you use 'foreach' versus 'map' versus 'grep'?
- What is the difference between use File::Find and use File::Find () and require File::Find?
- What is the difference between 'my', 'local' and 'our'?
- In a regex, how do you do non-capturing parens?
- In a regex, what's the difference between "greedy" and "non greedy"?
- What is a regex assertion? Which ones have you used?
Given a list of numbers, namely:
my @oldlist = ( 4, 7, 8 );
write some code to add 42 to every item in this list,
producing a new list. For this example data,
newlist should contain the values: ( 46, 49, 50 ). Sample answer:
my @oldlist = ( 4, 7, 8 );
my @newlist = map($_ + 42, @oldlist);
Given a string containing a space-separated list of names:
my $names = "freddy fred bill jock kevin andrew kevin kevin jock";
write some code to produce a frequency table of names, sorted
descending by frequency, then ascending by name.
For this data, the output should be:
kevin : 3
jock : 2
andrew : 1
bill : 1
fred : 1
freddy : 1
Sample answer:
my $names = "freddy fred bill jock kevin andrew kevin kevin jock";
my %freq;
for my $name (split ' ', $names) {
++$freq{$name};
}
for my $k (sort { $freq{$b} <=> $freq{$a} || $a cmp $b } keys %fre
+q) {
printf "%-10s: %d\n", $k, $freq{$k};
}
Given an input text file and an output file as follows:
my $infile = 'in.tmp';
my $outfile = 'out.tmp';
write some code to read infile and change all occurrences of
'Peking' to 'Beijing', leaving infile unchanged and writing
the changed text to a new file outfile. Sample answer:
my $infile = 'in.tmp';
my $outfile = 'out.tmp';
open(my $fhin, '<', $infile) or die "error: open '$infile': $!";
open(my $fhout, '>', $outfile) or die "error: open '$outfile': $!"
+;
while (my $line = <$fhin>) {
$line =~ s/\bPeking\b/Beijing/g;
print $fhout $line;
}
close($fhin);
close($fhout);
If they use
s/Peking/Beijing/g contrast with
s/\bPeking\b/Beijing/g and ask which they prefer.
Updated: Added \b assertions to s/Peking/Beijing/ and extra questions around regex assertions. Thanks haukex.
References Added Later
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.