Interview Qs for Perl Developers

Although not as popular as it once was, Perl still enjoys a loyal following. The open-source programming language was not only named the ninth most popular coding language of 2014 by CodeEval, it continues to garner support from users through grassroots organizations such as PerlMonks and Perl Mongers.

To find Perl-related jobs, click here.

Interview Qs“Perl has many advantages as a general-purpose scripting language,” said Bruce Gray, a consultant with Gray & Associates and member of the Atlanta Perl Mongers. “Experienced programmers take advantage of Perl’s uniquenesses, including the vast repositories of tested code that have accumulated over time.”

Here are some of the interview questions Gray asks to assess a developer’s knowledge of Perl’s unique features and resources.

As you know, hashes are one of the most powerful components of Perl. So how would you initialize the following hash: Key ‘A’ with value 1, key ‘B’ with value 2 continuing all the way through to key ‘Z’ with value 26?

  • What Most People Say: “May I write my answer on the whiteboard? Great, here you go:

 %hash = (
A => 1,
B => 2,
# –snip–
Z => 26,

  • What You Should Say: “I know two different ways to initialize that hash. May I write my code on the whiteboard? Great, here’s the first way:

@hash{ ‘A’ .. ‘Z’ } = 1 .. 26.

And here’s another option:

$count = 1;

%hash = map { $_ => $count++ } ‘A’ .. ‘Z’;

  • Why You Should Say It: The last two hash initializations are more concise, reducing the possibility of error. In addition, demonstrating familiarity with Perl’s range operator, alphabet increment, and either hash slicing or map() are signs of an advanced programmer.

What do the symbols in front of Perl variables signify?

  • What Most People Say: “The symbols show the type of variable: $ for single things (scalar), @ for multiple things indexed by number (array) and % for multiple things indexed by string (hash).”
  • What You Should Say: “Those symbols are called ‘sigils’ and signify the usage of the variable. For instance, $scalar @array %hash when using the entire variable, $scalar $array[index] $hash{key} when single values are used, @array[i1, i2…] @hash{k1, k2…} when multiple values (slices) are used.”
  • Why You Should Say It: The second answer is not only more complete, it demonstrates familiarity with array and hash slicing. You’ll get bonus points for knowing that the symbols are called “sigils” and that they are “noun markers” for the language.

What’s your favorite way to search CPAN?

  • What Most People Say: “What’s CPAN? Oh, it’s some sort of code repository. I only search archives that have been approved and installed by my company.”
  • What You Should Say: “I love the Comprehensive Perl Archive Network (CPAN), because it really saves time when I’m coding. I search the archives via or Or, sometimes I even use Google.”
  • Why You Should Say It: CPAN is the most important part of the Perl ecosystem. It’s a central, well maintained repository of tens of thousands of Perl modules. Nearly 95 percent of the solutions programmers need are free and widely available. In fact, not checking CPAN for solutions to coding tasks will cause you to reinvent and maintain many, many wheels.

Upload Your ResumeEmployers want candidates like you. Upload your resume. Show them you’re awesome.

Which values are true and which values are false in Perl?

  • What Most People Say: “Zero and undef are false; everything else is true.”
  • What You Should Say: “Numeric zero, string zero, the empty string, the empty list, and undef are all false; everything else is true.”
  • Why You Should Say It: Because forgetting about any of the false cases is a common source of bugs.

When do you use strict or warnings?

  • What Most People Say: “I only use them when it’s convenient, or when I’m trying to fix a bug.”
  • What You Should Say: “I always use strict and warnings. The only exceptions are when I’m creating quick one-liners on the command line or retrofitting code.”
  • Why You Should Say It: Strict and warnings are Perl’s safety features sort of like seat belts or motorcycle helmets. They can help you spot errors quickly and find the root cause. It’s a red flag if a programmer doesn’t use them or understand their advantages. Using strict and warnings should be a habit.

What’s the difference between the following two lines?

while (<$filehandle>) {…}

for   (<$filehandle>) {…}

  • What Most People Say: “Both lines of code read a file, but one is faster than the other, although I’m really not sure why.”
  • What You Should Say: “One search is more efficient than the other, because the while() loop reads one line at a time, whereas the for() loop reads the entire file at once, then loops over it one line at a time.”
  • Why You Should Say It: Using for() to read a large file is inefficient because it eats up huge amounts of memory. In fact, it’s a common bug that experienced programmers universally avoid.

Related Articles

6 Responses to “Interview Qs for Perl Developers”

  1. Kent Fredric

    Re Hashing: I’d be inclined to use either the first form, or the last form, but not the middle one.

    Mostly because I’d imagine the middle variation to be more confusing to beginner or intermediate programmers, and obvious code is often superior to “Smart” code.

    There’s also room for mistakes with the middle variation as I’m always likely to write it $hash{ } first where I should write it @hash{ }, and have to have an iteration where I realise my mistake and fix it.

  2. I would add that interview questions are going to vary a lot depending on the kind of work the job is for. I work primarily in web development using a core of popular open source Perl frameworks, so once dispensing with the basics I’d probably see how well a given applicant actually knows how to use the tool I am using on the team.

    For an expanded list of ‘the basics’ which I tend to use during a phone screener type interview (30 minutes or less to weed out the weak) check out this blog series: