The 1998 Perl Quiz Show

Jon Orwant

At the Second Perl Conference last August, I wrote and moderated the first-ever Perl Quiz Show. Four three-person teams competed for a variety of delicious prizes: Perl Resource Kits, TPJ subscriptions, TPJ Magnetic Perl kits, Perl Mongers T-Shirts, and O’Reilly gift certificates.

There were two semifinal rounds and one final round; each round pitted two teams against one another with fifteen toss-up questions. Toss-ups are questions answered by individuals; each correctly-answered toss-up earns ten points and the right for the entire team to collaborate on a bonus question worth up to thirty points.

Here, then, are all of the toss-up and bonus questions I wrote, including several that weren’t asked. If the toss-ups seem simple, bear in mind that merely knowing the answer isn’t enough – you also have to answer it before the other team buzzes in.

Toss-up Questions

Toss-up 1: In a regular expression, you can use curly braces to specify how many times you want to match something. For instance, x{5,10} matches at least five but no more than 10 x’s. What is the maximum number of occurrences you can match with this technique?

Toss-up 2: Guess that switch: Every once in a while, someone tells me they wish they could use #if and #ifdef statements in Perl. They can; all they need to do is use this flag.

Toss-up 3: Guess that variable: what scalar contains the name of the operating system you’re on?

Toss-up 4: A tangent function, a floor function, a function to generate temporary filenames. These are all part of what module bundled with Perl, meant to provide a uniform way of calling functions independent of what operating system you’re on?

Toss-up 5: Let’s say you have a digital clock that displays twelve-hour time (that is, it displays AM and PM). Ignoring the colon, what’s the smallest power of two that will appear on the display?

Toss-up 6: Continuing with the previous question, what’s the largest power of two?

Toss-up 7: Spin The Black Circle, Who You Are, Jeremy, Evenflow. These are songs by a Seattle grunge rock band with a two-word name of particular relevance to this conference.

Toss-up 8: It’s the only Perl program I know of that has been tattooed on a forearm. This cryptographic scheme was invented in 1977 by three MIT graduate students: Ron Rivest, Adi Shamir, and Len Adleman.

Toss-up 9: If you have multiple _____________ in your Perl program, they’ll be executed in reverse order: the last one will be executed first, and the first one last. This behavior is the opposite of the BEGIN block.

Toss-up 10: $_ has two characters, @ARGV has five. This symbol is arguably the only single-character variable in Perl. It’s a special filehandle used to speed up calls to stat, lstat, or any of the file tests.

Toss-up 11: The first day of the year is always a Monday, somewhere between December 29th and January 4th. That’s according to the standard year of this organization responsible for POSIX.

Toss-up 12: The hex() function converts a hexadecimal number to decimal. What function would you use to convert back to hex?

Toss-up 13: Back Orifice ‘98 allows you to remotely control the Windows 95 and 98 desktops. For ten points, name the group responsible.

Toss-up 14: A 233-MHz 750 PowerPC processor, a 4GB hard disk drive, 32MB of memory, built-in networking, an internal modem, a CD-ROM drive, and no floppy drive. What is this computer, released by Apple in August 1998?

Toss-up 15: A Frankenstein language created with pieces of JavaScript, cascading stylesheets, and HTML. That’s how WIRED News describes this variant on HTML that lets you enhance HTML with animation.

Toss-up 16: "The Lurking Horror", "Planetfall", "Leather Goddesses of Phobos", and the classic "Zork" were all games produced by what company?

Toss-up 17: A pragma is like a module - you invoke it with use - but it affects how Perl interprets your program. Which pragma is most likely to speed up the typical Perl program?

Toss-up 18: Definitions of croak() and confess() are found in which module?

Toss-up 19: Sarah Ophelia Cannon’s hat resides at the National Museum of History. The hat, with the price tag still attached, symbolizes Cannon’s character at the Grand Ole Opry, a homophone with the little program that Perl uses to build itself.

Toss-up 20: If Perl 5 were designed from scratch, these two functions (which currently exist in both Perl 4 and Perl 5) probably wouldn’t be there, because everything you can do with them you can now do with the tie() function. They let you store hashes on disk.

Toss-up 21: Give me the two common ways to access (but not modify) the last element of the array @bar.

Toss-up 22: What does this display?

print print print print print

Toss-up 23: This selfish-sounding keyword didn’t exist before Perl 5. It’s a faster and safer way to declare variables than local().

Toss-up 24: This word is the name for what a pearl is before it’s big enough to be called a pearl, but is better known in biology as the protoplasmic center of a cell in control of growth and metabolism.

Toss-up 25: Someone comes up to you and says that use strict is broken, because they say $a = $[; use strict; and no error occurs; they were expecting to see Global symbol 'a' requires explicit package name. What Perl function is responsible for this crime of omission?

Toss-up 26: There’s no difference between the foreach and for operators, but those aren’t the answers to this question. Two Perl operators that manipulate strings are 100% synonymous. What are they?

Toss-up 27: When I write a smiley face, it’s a colon followed by a hyphen followed by a right parenthesis. Consider the three scalar variables $:, $- , and $). Which one will vary from user to user on the same system?

Toss-up 28: Gem, moo, six, miss. Which of these words couldn’t you find immediately after the second slash of an m// pattern match?

Toss-up 29: $x is set to fuzz. What is $x++?

Toss-up 30: tr/a-z//; What does that do?

Toss-up 31: In a Perl regular expression, how do you create a grouping without creating a backreference?

Toss-up 32: What’s the sum of the protocol numbers for SMTP, FTP, and telnet?

Toss-up 33: The 1997 Ig Nobel Prize for Communications went to this man, the president of Cyber Promotions and widely-acknowledged King of Spam.

Toss-up 34: "Join us now and share the software." This is the first line of a song by a MacArthur grant winner who hangs out at MIT, wrote Emacs, and founded the Free Software Foundation.

Toss-up 35: This built-in function constructs a linked list of every character in a string, and is sometimes invoked before expensive pattern matches. It’s what good little boys and girls do after school.

Toss-up 36: What command-line switch checks the syntax of Perl programs?

Toss-up 37: "When you say it to your computer, the terminal may become slightly moist." This was said by Donald Knuth, describing what text formatting package of his own design?

Toss-up 38: He'll be twenty years old next year and underwent a five-hour operation on a brain tumor in 1991. The operation was successful, allowing him to enjoy his title as recipient of the world's most postcards - 33 million inall, thanks to a massive Internet campaign.

Toss-up 39:

hash_PeRlHaSh = hash_PeRlHaSh * ____ + *s_PeRlHaSh++;
This line of Perl code comes from the file hv.h in the Perl distribution, and it’s what Perl uses to convert the keys of your hash into its internal representation. The number that goes in the blank is a power of two plus one. It’s two digits, and both digits are the same. What is it?

Toss-up 40: To help the Perl development team debug Perl, you decide you’re going to write a program that generates and executes random Perl programs. You exclude functions like system() and unlink() and syscall() and open() and kill() that directly affect your operating system or any other processes running on your computer. You leave your program on all night, and in the morning you discover that many of your programs crashed. What four-letter function is the culprit?

Toss-up 41: What’s the longest function name in Perl?

Toss-up 42: Initial etic inquiry typically yields particles whose wave or field relationships (i.e., situatedness) to other particles are undetected, indistinct, or ambiguous and which must be identified before progress can be made toward emic understanding. This description of something called "eticity" is a core definition of what field of compuational linguistics that influenced Larry’s design of Perl?

Toss-up 43: "If there is a Perl 6, Perl 7 will be built out of sticks and stones." I made that up, but it’s an allusion to a statement about World Wars 3 and 4 by what famous physicist known for his Theory of Relativity?

Toss-up 44: Perl is free software. If you redistribute it, you can choose between two completely separate licenses: the GNU General Public License, and what other license?

Toss-up 45: Assuming a default Perl configuration, which of these four code snippets will beep?

print "\a" if $[;
print "\007" if $0;
print "\x7" if $$$;

Bonus Questions

Bonus 1: I'm going to make four statements about values that a scalar can hold. After each, you tell me whether the statement is true or false, for five points each.

  1. Every string is true except for the null string.
  2. Every number is true except for the quantity 0.
  3. Every reference is true.
  4. Every undefined value is false.

Bonus 2: I'll give you three lexically scoped variable declarations. Which are valid? Answer yes or no.

my $_;
my $::dog;
my $big{dog};

Bonus 3: Pencil and paper ready: give me a regular expression that matches these three misspellings of O'Reilly:
Oreilly O`Reilly O Riley
...but not match these two misspellings:
Or Reilly Oh really O'Rwant

Bonus 4: I'll give you four partial Larry sayings. You complete them, for ten points each.
"Down that path lies madness. On the other hand, the road to hell is paved with ________________."
"It's easy to solve the halting problem with __________."
"The three principal virtues of a programmer are ____________."

Bonus 5: Write a Perl one-liner that can be executed from the command line. The one-liner should take a file and replace each tab with a space, but use no more than six letters to do so. You don't have to count Perl or the filename, but it does have to count command-line switches.

Bonus 6: If you say 3 + 4 * 5 without any parentheses, the answer is 23 and not 35 because of something called precedence. * has a higher precedence than +, so it steals the 4 away from the 3. Rank the precedence of these five Perl operators from lowest to highest. You get an extra five points if you get them all correct. ++ ** == .. ||

Bonus 7: I'll give you four comments. After each one, you tell me whether the comment appears in the Perl source code, for five points each.
"And you'll never guess what the dog had in its mouth." "Here there be dragons."
"I'm not insane, you're insane, and you're trying to steal my magic bag."
"It all comes from here, the stench and the peril."

Bonus 8: Collecting demographic information about Perl is difficult because there's no central distribution point, and there's no registration process. So we'll treat the Perl Journal subscriber list as representative of the Perl community as a whole. After the United States and United Kingdom, which six countries have the most Perl programmers, for five points each? You don't have to order them.

Bonus 9: Caffeine is the drug of choice for programmers. I'll give you four drinks; you rank them in order from least caffeinated to most caffeinated for five points each. Mountain Dew, Pepsi, Jolt, and Coca Cola. For ten extra points, where does one tablet of Excedrin fit into this list?

Bonus 10: People complain about Perl's unreadability, but there are many ways to write crystal-clear Perl code. One of those ways is the module, which lets you use verbose alternatives to the sometimes cryptic scalars that Perl predefines for you. For instance, instead of saying $_, you can say $ARG. I'll give you five English names; you give me the Perl scalar it represents. MATCH, INPUT_LINE_NUMBER, OUTPUT_AUTOFLUSH, FORMAT_LINES_PER_PAGE.

Bonus 11: Usenet started as a 300-baud connection between which two universities?

Bonus 12: Full credit if your answer is within a factor of 10: How many black market kidneys could Microsoft buy? I'm assuming the August 14, 1998 market capitalization of Microsoft and the price of one kidney quoted in the famous piece of Internet folklore. Assume that Microsoft wants to corner the kidney market and is willing to spend its entire net worth to do so.

Bonus 13: Rank the following in order of occurrence:
IRC is launched.
Perl is introduced to the public.
The acronym "FAQ" first appears on Usenet.
Intel introduces the 80386 CPU.

Bonus 14: Rank the following in order of occurrence:
The Communications Decency Act is introduced.
DOOM is released.
Altavista is launched by Digital.
33.6 kilobit modems are introduced.

Bonus 15: You've heard of MP3s, the CD-quality audio format that's giving music producers the shivers about this Internet thing. MP3 stands for MPEG-3; MPEG is a digital video format. What do the four letters M, P, E, and G stand for?

Bonus 16: After I finish reading this question, I'm going to ask the crowd to choose whether they prefer vi to Emacs. Will substantially more people choose vi, substantially more people choose Emacs, or will the two be roughly equal?

Bonus 17: Write a syntactically perfect program that prints "yes" if a number is evenly divisible by 10. The number will be provided as an argument to the program. I'll give you a little extra time.

Bonus 18: Rank these code snippets from slowest to fastest:

A) print "$c$d";
B) print $c, $d;
C) print $c . $d;

Bonus 19: Expand these four acronyms, for five points each. CGI, FQDN, URL, ISDN.

Bonus 20: Expand these four acronyms, for five points each. TCP, SMTP, MIME, XML.

Bonus 21: Expand these four acronyms, for five points each. IANAL, CERT, API, FTP.

Bonus 22: I'm going to name six cities. After each, you tell me whether it has a Perl Mongers chapter, yes or no.
Toronto, London, Redmond, Washington, Paris, St. Louis, Helsinki.

Bonus 23: The Perl source code is peppered with Tolkien quotes. For ten points each, what are the three books in Tolkien's Lord of the Rings trilogy?

Bonus 24: Pencil and paper ready. Take the area code of this hotel and subtract from it the number of bones in the adult human body. You'll end up with the area code for a U.S. city commonly known by a two-letter abbreviation, or four characters if you count punctuation. Give me a pattern that precisely matches that four character abbreviation.

Bonus 25: I use the mSQL DBD to do CRUD. There are three database-oriented acronyms here: mSQL, DBD, and CRUD. For ten points each, what do they stand for?

Bonus 26: I'll name six modules. After each, you tell me whether it exists on the CPAN, for five points each. Search::Patent, Text::GenderFromName, Mortgage::Calculate, D'oh, Lint, Business::UPS.

Bonus 27: I'll give you an operating system or computer, you tell me whether Perl runs on it, yes or no, five points each. BeOS, Cray, Amiga, PalmPilot.

Bonus 28: I'll give you three built-in Perl functions; you tell me what prototypes they would have if you were writing equivalent subroutines. join, keys, pipe.

Bonus 29: When you apply the built-in ref() function to an object, you get the name of the object. When you apply it to a non-object reference, you get one of six answers. For five points each, what are they?

Bonus 30: Consider the scalar $X::Y::Z. X and Y are both packages. What is the relationship between X and Y?

Bonus 31: I'm going to list five functions. For each, tell me whether it's built into Perl 4, Perl 5, both, or neither. reverse, bless, eval, tag, abs

Bonus 32: Many of Perl's operators can be made into assignment operators by adding an equals sign. For instance, $a + 4 adds $a and 4, but $a += 4 adds $a and 4 and sticks the result in $a. I'll give you four operators; you tell me which can be made assignable by adding an equals sign. Answer yes or no after each. x, ^, &, &&.

Bonus 33: Laptops in the movies! For ten points, name the movie in which alien ships are infested with a virus uploaded from a PowerBook. For another ten, name the Tom Cruise movie in which we briefly see lists of Usenet groups scrolling by on a laptop.

Bonus 34: I'll give you three code snippets. For ten points each, tell me which module bundled with the Perl distribution contains the snippet.

print $query->textfield( -name => 'field_name' ...
@type = qw/Author Bundle Distribution Module/;

Bonus 35: Many people don't know that Perl comes with its own built-in symbolic debugger, perhaps because Perl programs practically debug themselves. It's invoked with the -d switch. I'll give you a debugger command, and you tell me what it does, for five points each. lower case b, lower case x, lower case h, lower case s.

Bonus 36: What does this print?

perl -e '$-=$=; print $––– - ––$–'

Bonus 37: You have a hash, and you know it's been tied to some package. Which two functions should you use to find out what package that is?

Bonus 38: Entropy coding (and more to the point, common sense) dictates that you should use short terms to represent commonly-occurring concepts. That's why Morse code uses a dot for E and a dash for T. You see this all over Perl, too. For five points each, give me a three, four, five, six, and seven letter builtin Perl function.

Bonus 39: There are five tokens beginning and ending with double underscores that have special meaning to Perl. What are they?

Bonus 40: Name that file test. I'll give you five operations. For five points each, you give me the single-letter file test that performs that operation. Don't forget to specify whether the letter is lower or upper case. Is the file there? Is it a binary file? Is it empty? How long has it been since the last access? How big is the file?

Bonus 41: Which modules are bundled for the first time with 5.005? I'll give you six modules that might or might not exist; answer yes or no after each.,,,,,

Bonus 42: There's always more than one way to do it, but can you tell me the two most concise ways to make Perl add a newline after each print?

Bonus 43: The caller() function returns information about the environment in which it was invoked. If it's invoked with no arguments inside a subroutine, it tells you three things. For ten points each, what are they?

Bonus 44: This little known technique lets you transform your Perl program as it's being interpreted. For instance, you can use this to encrypt your source code and have Perl decrypt it on the fly. For all twenty points, what is this technique?

The Answers

Below, I capitalized the portion of the answer that the player needed to say for full credit.


T1: 65535
T2: -P (make them specify capitalization)
T3: $^O
T5: 128
T6: 1024
T9: END blocks (also accept END subroutines)
T10: _
Sean Mahoney, age 16, got this one. Why am I not surprised?
T14: The IMAC
No one got this. Depressing.
T21: $bar[-1] and $bar[$#bar]
T22: 1111
print returns 1 on success.
T23: MY
T26: TR and Y
T27: $)
$) contains a list of group IDs.
T28: GEM
You can increment letters as well as numbers. a plus one is b, y plus one is z, and z plus one is aa. So fuzz plus one is fvaa. You can't decrement them, though.
The player buzzed in and said "It's a no-op." I declared that incorrect. Then some rube in the audience yelled out that if $_ were empty, the compiler would optimize away the statement, so that it actually would be a no-op. I don't think that's what he was thinking, but I awarded full points anyway.
T31: (?: )
T32: 69
FTP is 21, telnet is 23, and SMTP is 25. Someone pointed out that FTP could have another port number, and so the answer isn't unique. However, the team answered 69, getting full points, so it's moot.
T33: Sanford WALLACE
T34: Richard STALLMAN

Linked Bonus: For all twenty points, your entire team has to sing the next line of the song in unison.
Answer: "You'll be free, hacker, you'll be free." No points awarded; the team didn't know the next line. After I read the answer, someone in the crowd yelled out for me to sing it. Security detained him after the show.

T36: -c
T37: TEX
(According to Knuth, "Insiders pronounce the X of TeX as a Greek chi, not as an 'x', so that TeX rhymes with the word blecchhh.")
T39: 33
Spoken from personal experience.
T43: Albert EINSTEIN

Bonus answers

B1: F (consider "0"), T, T, T.
B2: NO
B3: can vary. /O.?Re?il/
I shuffled this question to the end because it's too open-ended. It was never asked.
B5: perl -pi -e 's/\t/ /g'
B6: .. || == ** ++
B7: YES (mg.c), NO, NO, YES (Frodo said that in toke.c.)
Just for kicks, the next six are Sweden, Holland, Norway, Denmark, Finland, and Italy.
B9: PEPSI (38 mg/12 ounces), COCA-COLA (45.6 mg), MOUNTAIN DEW (54 mg), JOLT (72 mg). Excedrin is between Mountain Dew and Jolt.
Canadian Mountain Dew has no caffeine.
B10: $& $. $| $=
B12: 25,690,000 kidneys. (Accept between 2,569,000 and 256,900,000 kidneys).
(Market cap of Microsoft is $256.9 billion. Kidneys are a steal at 10 grand.)
B13: Intel introduces the 80386 CPU (June 86)
Perl is introduced to the public. (Jan 88)
IRC is launched. (May 89)
The acronym "FAQ" first appears on Usenet. (Sept 89)
B14: DOOM is released (Dec 93)
The Communications Decency Act is introduced (Feb 95)
Altavista is launched by Digital (Dec 95)
33.6 kilobit modems are introduced (Jan 96)
B16: (Depends on crowd response)
vi got more applause, much to my chagrin.
B17: print "yes" unless shift() % 10 is one possible answer.
I didn't ask this because it was too open-ended.
B18: A-C-B
The team didn't fall into my trap. I'd hoped that they'd answer Universal Resource Locator.
The team got hung up on the first one, trying desperately to complete "Internet Assigned Numbers Authority ___". Tom Phoenix pointed out that CERT had recently declared that their name was –poof!– no longer an acronym.
B22: Toronto NO, London YES, Redmond NO, Paris NO, St. Louis YES, Helsinki NO
Mongers groups exist in some of these places now, but not at the time of the quiz show.
B24: /D\.C\./
The team said \w+, but that won't handle the dots.
B26: Search::Patent NO, Text::GenderFromName YES, Mortgage::Calculate NO, D'oh YES, Lint NO, Business::UPS YES
B27: BeOS YES, Cray YES, Amiga YES, PalmPilot NO
Ken Albanowski wrote a Perl API to the PilotLink library, which lets you develop Pilot applications in Perl.
     join          $@
     keys          \%
     pipe          **

But it turns out there are more: LVALUE and IO.
B30: There is none.
B31: reverse BOTH, bless PERL 5, eval BOTH, tag NEITHER, abs PERL 5
B32: x YES, ^ YES, & YES, && YES
The team receiving this bonus wasn't doing so well, so when the time they got to the last (and hardest) item, I pointed out that the author of this module (Mike Stok) was sitting in the front row. Didn't help 'em.
     lower case b         Set a BREAKPOINT
     lower case x         Evaluate and PRETTY-PRINT
                          (Prints nested data structures too)
     lower case h         Displays HELP
     lower case s         Single-STEPS through the code

B36: 2
(The print statement is equivalent to saying x – (x – 2), so it'll be 2 in almost every circumstance.) Chip Salzenberg came up to the stage afterward and pointed out that the order of evaluation of the arguments isn't guaranteed by Perl, so the answer wouldn't necessarily be two on all implementations. I stand by this answer, because I've yet to see a Perl implementation that evaluates the second argument of – before the first. (Now Chip will patch Perl just to spite me.)
B37: REF and TIED.
B38: One possible set of answers: pop, push, sleep, scalar, reverse.
B39: __FILE__, __LINE__, __PACKAGE__, __DATA__, __END__
Is the file there? -e
Is it a binary file? -B
Is it empty? -z
How long has it been since the last access? -A
How big is the file? -s
B42: -l and $\ = "\n"
B43: The PACKAGE, the FILENAME, and the current LINE.
The answer given was FILTER. I declared it incorrect.


The actual quiz show scoring was ten points for a correctly answered toss-up, minus five for interrupting a toss-up and answering incorrectly, and anywhere from twenty to thirty points for a bonus, with partial credit offered.

Remember that these were questions given to teams of people, not to individuals, so you shouldn’t expect to do very well. But if you simply must quantify your score, count one point for each correct answer (rounding partial credit on bonuses) and sum.

0-20: Perl Intern. Hit head with board, read FAQ, retake test. Beware Aquarius.
21-40: Perl Dentist. Keep telling yourself that you would have scored a lot higher if you’d used the online documentation, and really isn’t that a better way to gauge programming competence. Create dissent between Scorpios and Libras.
41-60: Perl Orthopedist. Feel guilty for peeking at the answers, disagreeing with them, and deciding that you’re really correct. A Taurus will cut you off on the freeway.
61-80: Perl Neurosurgeon. Your future holds satori and high consulting fees. Expect a lawsuit from a Gemini.
81+: You already knew the answers because you attended the quiz show in person. Shame on you for pretending that you really did this well. If a Sagittarius offers to duel, refuse.


Jon Orwant is editor and publisher of The Perl Journal and an MIT Media Lab IBM Fellow.