# 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:

``` A
COMPREHENSION ABILITY OLD
ALWAYS
SCIENCE AND PHYSICS
ANY
AS
...```

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;\$_=pop@x;
```

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

```\$ ./nocoug.pl 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?

Interested in working with Yanick? Schedule a tech call.

#### Yanick Champoux

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

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.