Inspired by the original thread and the up and coming clones, here's one for the Perl community.
What are questions a good Perl programmer should be able to respond to?
Inspired by the original thread and the up and coming clones, here's one for the Perl community.
What are questions a good Perl programmer should be able to respond to?
my
and our
?my
and local
?Questions
Explain the difference between these lines of code and the values of the variables.
my $a = (4, 5, 6);
my @a = (4, 5, 6);
my $b = 4, 5, 6;
my $c = @a;
What are some of Perl's greatest strengths?
use strict;
do? Why is it useful?What does the following block of code do?
print (3 + 4) * 2;
Tests
grep
using map
.perldoc
.my $x = ...
and my($x) = ...
?my($x,undef,$z) = ...
do?my(@a,@b) = (@list1, @list2)
likely a bug?my $a = 1;
if($a) {
my $a = 2;
}
print $a;
What is the value of $a at the end?
Write code that builds a moderately complex data structure, say an array of hashes of arrays. How would you access a particular leaf? How would you traverse the entire structure?
What is the difference between
if ($foo) { ... }
and
if (defined $foo) { ... }
and when should you use one over the other?
For each of the following problems, how would you solve it using hashes?
What's wrong with this code?
my @array = qw/a b c d e f g h/;
for ( @array ) {
my $val = shift @array;
print $val, "\n";
}
My bellweather question is What's the difference between a list and an array?.
I also tend to like asking people to show me as many ways as they can to define a scope. There's one that people almost always forget, and another that most people think provides a scope but doesn't.
I think brian d foy's approach is an ingenious tactic to test knowledge, understanding, and partiality about the language and the programming craft in general: What are five things you hate about your favorite language?. If they can't name 5 they probably aren't great with the language, or are totally inept at other approaches.
He applies this to people trying to a push a language: I would extend that and say it is just as applicable here. I would expect every good Perl programmer to be able to name five things they don't like. And, I would expect those five things to have some degree of merit.
What is a lexical closure? When are closures useful? (Please, no counter-creators!)
My favourite question. What is following code missing:
open(my $fh, "<", "file.txt");
while (<$fh>) {
print $_;
}
close($fh);
This question should open discussion about error handling in perl. It also can be adopted to other languages too.
What is the difference between list context and scalar context. How do you access each? Is there such a thing as Hash context? Maybe a little bit?
I would also probably dig on regex, as I expect every good Perl programmer to master regex (but not just that). Some possible questions: