Thursday, September 03, 2009

Just another Perl hacker

I was lucky enough to stumble onto the first JAPH I ever wrote - a whole two days after I first started learning Perl back in 2004.

It turns out to be something of a word game:

perl -e '$c="ePreh";$k="tonat";$h="ckeJ";$a="ahlr";
$e=reverse($e);$e=~s/stan/st an/;$e=~s/rP/r P/;$e=~s/rlh/rl h/;

And an analysis with strict, warnings, and mys added (spoiler warning):

/usr/local/bin/perl -w
use strict;
my $c="ePreh";
my $k="tonat";
my $h="ckeJ";
my $a="ahlr";
$h=reverse($h); # $h = "Jekc"
my $e=$h.$a.$c.$k."sur"; #$e = "JekcahlrePrehtonatsur"

# This next part makes my eyes cross when I look at it for too long.
# It switches the first and last character of $e.

$e=reverse($e); # $e = "JustanotherPerlhacker"
$e=~s/stan/st an/; # $e = "Just anotherPerlhacker"
$e=~s/rP/r P/; #$e = "Just another Perlhacker"
$e=~s/rlh/rl h/; #$e = "Just another Perl hacker"
$e.="\n";print($e); #append a newline to $e and print it out.

Good times!

No comments: