Sample answers to Christmas Quiz

Chris Jack chris_jack at msn.com
Thu Dec 18 18:17:18 GMT 2008


Having written the quiz, and as actual answers seem to have faded to a trickle, I thought I ought to offer some sample answers of my own. Apologies ahead of time for any line break issues - but I have tried my hardest to avoid them!
 
1) Name as many different reasons Larry Wall has given for how Perl came to be named (including where he has given them) as you can. Make up a brand new reason of your own.
 
 
>From Wikipedia:
 
 
Perl was originally named "Pearl", after the Parable of the Pearl from the Gospel of Matthew. Larry Wall wanted to give the language a short name with positive connotations; he claims that he considered (and rejected) every three- and four-letter word in the dictionary. He also considered naming it after his wife Gloria. Wall discovered the existing PEARL programming language before Perl's official release and changed the spelling of the name.
 
 
While the name is occasionally taken as an acronym for Practical Extraction and Report Language (which appears at the top of the documentation), this expansion actually came after the name; several others have been suggested as equally canonical, including Wall's own humorous Pathologically Eclectic Rubbish Lister. Indeed, Wall claims that the name was intended to inspire many different expansions.
 
Perl gained it's name from knitting as it is often used to knit together data from many sources.
 
2) Name all the built in file handles in Perl.
 
 
STDIN, STDOUT, STDERR, ARGV, ARGVOUT, DATA
 
3) Write a Perl function that takes two references to arrays and returns the intersect of them. If an entry appears n times in array 1 and m times in array 2, the output should list that entry min(n,m) times. Bonus mark for one line solutions.
 
 
Lots of good answers, but I'm going to republish Jasper's solution which has the advantage of working plus looks appropriately unreadable and terse. I asked the perl proficient guy next to me what it did and he has yet to get back to me. I thought the use of "1x" was interesting and novel, albeit inefficient especially when there are lots of duplicates, and the use of a comma to avoid a semicolon obviously fudges the one-line bonus mark but nevertheless...:
 
 
sub intersect {grep(!++$_[2]->{$_},@{$_[0]}),grep 1x$_[2]->{$_}--,@{$_[1]}}
 
 
In the absence of the one line edict, which of course encourages bad style, this is a more readable version of basically the same algorithm:
 
 
sub list_intersect_duplicates {
 
    my($list1, $list2) = @_;
 
    my %hlist2;
 
 
    grep {$hlist2{$_}++     } @$list2;
 
 
    grep {$hlist2{$_}-- > 0 } @$list1;
 
}
 
4) How many different variable types are there in Perl? Be as sensibly voluminous in your answer as you are able.
 
 
I have been asked this in more interviews that I care to recall and generally interviewers seem to be looking for 3 (scalar, list, and hash) but code, filehandle, and format are also high level types.
 
 
You could also look at my, our, and local - and mention typeglobs, references (which in turn can be subcategorised), and read-only constants.
 
 
You could then differentiate between file handles and directory handles - and split scalars into the different ways they can be stored internally: e.g. as integers, doubles and strings.
 
 
There is also the internal special purpose magical object which is used to implement things like blessed objects and the various sorts of tied objects.
 
5) What animal is on the front of the Perl Cookbook (bonus mark for knowing both the first and second edition)?
 
 
Bighorn sheep (Ovis canadensis) on both editions.
 
6) What company was Larry Wall working for when he wrote Perl 1?
 
 
The Jet Propulsion Laboratory (JPL) at NASA. Did someone say rocket science?
 
7) What does the L in Randal L Schwartz stand for?
 
 
Lee.
 
8) Name a Perl module Leon (Brocard) has written (bonus mark if you've used it).
 
 
http://cpan.uwinnipeg.ca/search?query=Brocard&mode=author
 
9) When will Perl 6 be released?
 
 
Perl 6 is free so it doesn't need to be released.
 
10) Who was the most important pioneer of Perl Poetry?
 
 
Sharon Hopkins.
 
11) Write a limeric about Perl. Bonus mark for making it perl parseable.
 
 
<<_;
 
 
There was a perl hack from Nantucket,
 
 
Who wrote one-line scripts by the bucket,
 
 
He tried to write verse,
 
 
But twas longer and worse,
 
 
Especially since he didn't know any swear words.
 
 
_
 
 
12) What year was CPAN founded in?
 
 
1995
 
13) Think of a witty and/or interesting Perl Christmas quiz question and answer it.
 
 
Which 1998 movie featured a snippet of code from the Perl FAQ?
 
Sphere.
_________________________________________________________________
Get a bird’s eye view of the world with Multimap
http://clk.atdmt.com/GBL/go/115454059/direct/01/


More information about the london.pm mailing list