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.

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


In reply to Re: RFC: Self Assessment Perl by eyepopslikeamosquito
in thread RFC: Self Assessment Perl by LanX

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.