NoCOUG SQL Challenge – thinking outside the padded box

Posted in: Technical Track

Seems that our André Araujo has already spilled the beans and revealed his solution to the second edition of the NoCOUG SQL Challenge.

Now, I can’t let him have all the fun, can I?

Unfortunately, my SQL-fu is pathetically weak, so I stand no chance against his Querying Might. Buuut I am well versed in another art. A darker art. A terrifying art: Perl golf.

You might want to get the children out of the room before you continue reading. Pregnant women and the elderly might also want to avert their eyes. It ain’t going to be pretty.

… everybody with a weak stomach has left the premise? Good.

To be able to work with it, I’ve exported the riddle table into a space-delimited file, looking like this:


With the data in that format, I can now solve the riddle with:

#!/usr/bin/perl -p
s/ (\w+)/lc$&/e;$k{$1}=$_}{/ /&&s/[A-Z]+/$k{$&}/,$x[y---c]=$_
for(%k)x%k;[email protected];

While this script prints the secret message, it’s not very well formatted. If we want to be prettier, we can always do:

$ ./ data | perl -0lpe's/\s+/ /g'

For the time being, I’ll resist the urge to deconstruct and explain my solution. Instead, I’m going to add a meta-level to the challenge. Can you figure out how I’m solving the unspoken problem? And if you do, can you translate it into an Es-Cue-El invocation? While keeping some grasp on your sanity?

Want to talk with an expert? Schedule a call with our team to get the conversation started.

4 Comments. Leave new

BRAVO, Yanick! This is wickedly brilliant, mate! It took me some time to realize how it worked, especially, what the “}{” was for! :-)

Yanick Champoux
February 21, 2011 10:43 am

Thank you. :-) That’s what’s fun with Perl golf, it allows you to discover details and quirks of the interpreter than you rarely stumble upon in Real Code.

That ‘}{‘ trick, for example, is known as the “kissing inuits” operator in Perl circles, and is a good koan to help peeps understand what Perl’s command-line ‘-p’ parameter does behind the scene.

Iggy Fernandez
March 1, 2011 1:30 pm

Was that “kissing inuits” or “kissing eskimos” :-)

Yanick Champoux
March 1, 2011 2:56 pm

The original term, I think, was “kissing eskimos”. But up here in Canada we are not too fond of the ‘E’ word, and prefer ‘Inuit’. ( :-)


Leave a Reply

Your email address will not be published. Required fields are marked *