Clear questions and runnable code
get the best and fastest answer
Re: Token Abuse Japhby chargrill (Parson)
|on Feb 10, 2006 at 21:15 UTC||Need Help??|
I was also surprised that $ = was legal. Unfortunately,
perl -MO=Deparsespoiled that fun, as well as teaching me to look out for that in the future :)
Being thoroughly impressed by this (as well as the rest of liverpole's JAPH's, I thougt I'd go ahead and post a detailed de-obfuscation of this particularly clever (to me, at least) JAPH.
First, the obfuscated code:
Pretty confusing! But let's run it through -MO=Deparse, and we get:
Still pretty confusing, but at least now I can parse it a little better.
$= normally defaults to 60 as the current page length of the selected output channel, but this just sets it to 1.
$- = () = qw; ( );; is like $- = () = ('(',')');
('(',')') is a two element list, and the =()= idiom Perl Idioms Explained - my $count = () = /.../g shows that $- receives the count of elements in the list, in other words 2.
Equivalent to $* = 2 * 2 * 2, or 8.
Sets $/ to 10.
_: is a line label, and I thought (as Errto noted above) it had to be at the begining of a line. $=, the list separator for list values interpolated into
a double quoted string, defaults to a single space. The statement is
equivalent to $" = " " . chr 10 + 8 ** 2 , and ** binds tighter than + ,
therefore $" = " " . chr 10 + 64, or rather
This is: $/ = 10 >> 1 || $* * $-;
10 >> 1 will evaluate true (non-zero), so the right half doesn't gets evaluated, and $/ is subsequently set to 5.
This can be written as $/ = 5 & ~ 8 / 2 , or a bit more clearly, $/ = 5 & ( ( ~ 8 ) / 2 ). This has the net effect of setting $/ to 1.
Going to the "_" line label, $= (currently " J") has chr 1 + 64, or "A" appended to it. then 1 >> 1 evaluates to 0, so this time the right hand of the expression is evaluated, and $/ is set to 8 * 2, or 16. Then $/ = $/ & ~ $* / $- can be restated as $/ = 16 & ( ( ~ 8 ) / 2 ), and sets $/ to 16.
Back to the "_" line label. $= (currently " JA") has chr 16 + 64, or "P" appended to it. 16 >> 1 is 8, so $/ is set to 8. and 8 & ( ( ~ 8 ) / 2 ) evaulates to 8.
Back to the "_" line label, $= (currently " JAP") has chr 8 + 64, or "H" appended to it. Then 8 >> 1 is 4, so $/ is set to 4. And what I think is the really clever "bit" ;) is that now 4 & ( ( ~ 8 ) / 2 ) evaluates to 0, so and goto _; is skipped, proceeding to:
... which I think is pretty self-explanatory.
Whew! ++liverpole! That was a lot of fun!