Talk:Just another Perl hacker

From Wikipedia, the free encyclopedia

This article was originally based on material from the Free On-line Dictionary of Computing, which is licensed under the GFDL.

[edit] WTF?

How the heck can that program consisting only of keywords work? I just tried it out and it does work. But my experience of Perl is limited to debugging a very simple Perl script made by someone else, so I can't even begin to understand that mess. --JIP | Talk 15:23, 14 Apr 2005 (UTC)

Some of the "keywords" are actually quote operators, for example qw, qq, q, qx. So some of what looks like keywords are actually quoted strings, and it's taking the first letter of each word: "join use sub tied" -> "just"; "abs ne open tied hex exp ref" -> "another"; "printf each return local" -> "perl"; "hex alarm chdir kill exec return" -> "hacker". I haven't figured out exactly how it's turning that into a print statement - but I'm sure it would be a useful learning experience figuring it out!! --munt fish July 5, 2005 12:54 (UTC)
(Ack...this is my first comment, and I have no idea how to make the code sections line up correctly in my post...sorry)
Actually qx is never used as a quoting operator, which would be silly since it would have run the quoted text as a shell command. The two times it appears aren't words at all...the first uses the q as the delimiter for an s/// statement, and the x as a (meaningless) regex flag. The second uses the q as the delimiter for a qw() list, and the x as the delimeter for another s/// statement. Also notice that each of the strings you mention is quoted as a list (qw) instead of a string (q or qq), which makes it easy to use the words independently of each other. Anyway, to illustrate how it does the printing:
s qq qx xor
s x x length uc ord and print chr
ord for qw q join use sub tied qx
xor eval
roughly translates to:
s// /;  # $_ was undefined, now contains " "
s/ / length uc ord and print chr
ord for qw q join use sub tied q/;
eval $_;
or simply:
eval " length uc ord and print chr
ord for qw q join use sub tied q";
The statement inside the eval translates to:
foreach (qw( join use sub tied )) {
    print(chr ord $_);
}
"length uc ord" is always true (and has no other effects), so it's meaningless. "chr ord" translates one character to an integer ascii value and back, discarding the rest of the string. So when "print chr ord" is given each word in the list in turn, it prints the first letter from each one. — Bob9000, July 16, 2005, 11:58 UTC
I first posted the JAPH in question on Perlmonks as Fun with reserved keywords. There is a discussion in that thread, including a detailed spoiler. --Blokhead 15:58, 29 September 2005 (UTC)

[edit] Attribution

I'm the author of the last JAPH on the page, the one that has no alphanumerics or whitespace. I wrote it in August of 2004. I don't know how to attribute/cite this, because it doesn't appear on any web page of mine, only online on RPI lily (a CMC at rpi.lily.org).

Any suggestions? TIA.

Sue D. Nymme 14:46, 1 February 2007 (UTC)