My JAPH Deciphered

An annotated translation, into regular Perl, and layman’s terms, of the nugget of (apparent) nonsense I sometimes drop into my email signature.

For the uninitiated, JAPH stands for “Just Another Perl Hacker,” – it’s a tradition, amongst Perl programmers, to create tiny programs to output those four words in the most outlandish and esoteric of ways.

I chose to use the Lingua::Romana::Perligata module, which allows you to write your code in Latin, instead of the normal Perl syntax.

The original:

use Lingua::Romana::Perligata; # Barry Price - http://www.barryprice.co.uk/
da xis Just tum another tum Perl tum hacker. dum xis decapitamentum damentum
xo fac sic xum scribe egresso. nisi yum tum tres aequalitam fac sic lacunam
scribe egresso. cis. yo preincresce. cis. XLIV indementum scribe egresso.

Pretty nasty, even if you know Perl and Latin.

Now let’s format it, BSD/Allman style, still in Latin:

use Lingua::Romana::Perligata; # Barry Price - http://www.barryprice.co.uk/
da xis Just tum another tum Perl tum hacker.
dum xis decapitamentum damentum xo fac
sic
    xum scribe egresso.
    nisi yum tum tres aequalitam fac
    sic
        lacunam scribe egresso.
    cis.
    yo preincresce.
cis.
XLIV indementum scribe egresso.

Okay, that almost looks like a computer program. And it still compiles (at least, it does here, in Perl v5.8.4 on Debian). Now let’s see what it would look like in regular Perl – without the Latin insanity:

# Barry Price - http://www.barryprice.co.uk/
@x = ('Just', 'another', 'Perl', 'hacker');
while($x = shift @x)
{
    print $x;
    unless ($y == 3)
    {
        print ' ';
    }
    $y++;
}
print chr(44);

Calm down, I never claimed it was good code. The object of the exercise was to produce four lines of text with the ability to both bewilder, and compile!

The documentation is pretty good, but the key points to understanding it are:

  • The three variables @x, $x and $y are translated as xis, xo/xum (depending on case) and yo/yum (again, depending on case). The -um suffix indicates the accusative case, -o is the dative. Ah, high school Latin…
  • And yes, it’s a particularly evil feature of Perl which allows me to have two completely unrelated variables called @x and $x. And yes, the elements of @x would be referred to as $x[$_], which would still be nothing to do with $x. Anyway, back to the Latin:
  • da xis Just tum another tum Perl tum hacker translates as “give Just and then another and then Perl and then hacker to @x”. da is approximately the same as the equals (=) assignment, and tum in this context is the equivalent of a comma.
  • dum .. fac is the while() loop, and sic .. cis are the equivalents to braces in regular Perl. xis decapitamentum damentum xo translates as “behead @x and give it to $x”. Nice.
  • Within the while loop, xum scribe egresso is “write $x to an exit”. We then “write a hole to an exit, unless $y is equal to 3″.
  • $y? Where did that come from? How could it be equal to 3? Ah, well Perl will magically declare it for us at this point, with a value of null. So it can’t be three yet…
  • yo preincresce. “Increase $y”. Aha. On the first iteration, it will add 1 to null, which in this case makes 1. So on the fourth iteration, we print ‘hacker’ (the 4th array element), but not the space afterwards, since $y is 3.
  • This ends the while() loop, and now we just XLIV indementum scribe egresso. Or “give a name to 44 , and write it to an exit”. 44 is the ASCII code for a comma.
  • Oh, and why did I have to use chr() just to print a comma? Simply because the module didn’t seem to provide a “clean” way of doing it.

Phew. No more Perl for at least a week, I promise!

Premature Migration

This site was originally written from scratch in PHP, a language I hadn’t used for years (I’m a Perl programmer). The blog was a tiny addition, and so I used Blosxom, a tiny Perl script.

Anyway, I’ve become involved in writing WordPress plugins recently, so I thought it could be advantageous to use that here instead. So I just migrated the meagre few articles I’d already written through Blosxom, and the rest of the content will follow shortly.

I’m not even listed on Google yet, and I’m already doing the first site redesign. This is ridiculous…

Backticks on Windows

We had a fun situation at work this week, when our old and weary Exchange server gave up the ghost and died. We’d been planning to migrate it to a new server anyway, but we weren’t planning on doing it this week. Oh well, it was an incentive to get the move out of the way.

I’d already written a Perl script to migrate all of the clients to the new server. Not very elegant, it just sat on a machine with Domain Admin rights, and performed a remote registry edit of each client on the network, replacing the Exchange server settings in the registry with the details of the replacement server. I’d done a few test runs using ActivePerl under XP, and it had worked fine.

Unfortunately when we realised we had to migrate now, I didn’t have an XP machine to hand, and obviously the Windows administration tools that the Perl script required weren’t available on my Debian workstation. So we ran it on another Windows machine with Perl installed, and it failed.

A few minutes of frantic debugging later, we concluded that somehow the backslashes in the UNC paths were getting munged when Perl was passing them to the registry client via backticks (we needed to capture the output). This machine happened to be running Perl built for Cygwin, rather than ActiveState.

One install of ActivePerl later, the script was running along happily. I guess there’s a subtle (but big enough) difference between Perl for Cygwin and ActivePerl in the way they handle subprocesses run from CMD. You learn something new every day. But I think I’ll just stick to Perl on Linux…