Tag Archive for 'perl'

Reconstruction

The thing about backups is everyone knows they are critically important. It is like your lungs. You don’t sit around and think about your lungs everyday, all day. Yet, if you loose them, it is pretty much game over #

The quote, ironically, refers to Ma.gnolia, for whom I once created and maintained a wordpress plugin. Pure serendipity – I just searched Google for “the thing about backups” until I found a quote I liked…

But to get to the point, this website was first registered in 1999. Ten years ago. Since then, it’s hosted at various times a static site, a defunct mess, a Movable Type install, Wordpress, a Bloxsom install, an Habari blog, and then finally a return to Wordpress as I realised that it’s very obviously the least-bad blogging engine around at the moment. Even if it is written in PHP.
Continue reading ‘Reconstruction’

Eschew Obfuscation!

Sometimes Perl gets a bit of a bad rap for being a language in which it is trivially simple to write utterly unmaintainable code.

Today Slashdot even reviewed a book, Perl Medic, aimed at helping people to demystify the inner workings of their colleagues’ incomprehensible apparent line noise, posing as a supposedly high-level language.

I personally think Perl’s a great tool for getting the simple things done simply, and getting even the most complex of tasks done without too much in the way of hassle. Whatever you want to do, there is almost certainly a module freely available on CPAN to help you in doing so.

And yes, I generally make sure that my code uses both the strict and warnings pragmas, and try to use sane variable and sub naming schemes in anything more than a couple of lines long.

But it’s still always a bonus to be able to use such a behemoth of mind-bleedingly insane code as the gorgeous Mail::RFC822::Address module, as I did today. Yes, there are perhaps more reasonable ways to verify the integrity of a supplied email address, but I’m afraid I just rather like the idea of passing my input through this.

Y2K +38

Something I found myself writing earlier:

# Convert the 2-digit year into the 4-digit year
$y = '20' . $y;
# nb. this breaks for years after 2099.
# however, this server will have been broken for over 60 years by then anyway.

Having survived The Millennium Bug, will your systems die in the early hours of Jan 19 2038? Mine will…

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…