JAPH
print "Just another Perl hacker,";
Assignment: Write a JAPH
A JAPH is a bit of code that prints "Just another Perl hacker," There
is one at the install perl page. Check perlmonks for more.
Most of the time you want to write clear, readable code. JAPH's are just
the opposite. You try to twist the thing as much as possible. JAPH's are one
species of Perl obfuscated code, an art in itself.
For example, here is the letter "P", the hard way.
print chr 10*split/]/,"a]a]a]a]a]a]ab]c]" # I write this and looking back
a year later, there is one thing I can't figure out. Thanks Mary.
Writing a "JAPH" is a rite of passage for a Perl Hacker. People
will be in awe of you if you can write a good one.
Some ideas to get started
- Anything after # is a comment. Which means you can fill up your JAPH with
lots of totally irevelant characters with almost no thought.
- You can do a lot with split, join, map, reverse, and maybe the functions
that change numbers to their ascii representation.
- Use regex's, the tr function and any other you can find.
- Split lines in odd places.
- Use the default variables ( @_ and $_) as much as you can. They look weird
and are hard to see if mixed carefully into the code.
- If you use a number, make it hard. 4 is not as much fun as 1000+sqrt(4^2)-500-250-125-125
- Read the perlfunc page or your text to find some new functions to play with.
- All letters have a numerical equivalent and can be changed back and forth
using the chr() and ord() functions.
- Spend some time at Perlmonks reading the obfucated
code section. There are about 300 Japh's and other Perl oddballs here.
- Test your code
Some simple examples
Here I turn a list into a number, do some math on the number and turn it into
a letter;
First step by step;
| @_=qw(erk3 kerk3 k;;; er;er;; r;e e r; r;r; r;;) |
make a funky looking array, assigned to @_ |
| $_=@_ |
$_ now contains a number, the number of items in the list
@_ in this case, 9 |
| print chr $_ * $_ -$_+2; |
multiply 9 x 9, subtract 7 (-9 + 2 = 7) |
Now all together
@_=qw(erk3 k//rk3 k;;; er;er;;
r;e e r; r;r; r;;);$_=@_;print chr $_ * $_ -$_+2;
Even I can't decipher this mess. And this is only the first letter.