spaz has asked for the wisdom of the Perl Monks concerning the following question:

I thought I knew a little wacky Perl. Boy am I humbled now.
I found this lil beauty on the CPAN repository of JAPH's. It was the last entry.
I've run it through Deparse, that didn't help in the slightest.
I've run it through the Debugger, that only made things worse.

Will any monk much more enlightened than myself please help me understand?
$~='`';$_=$:=$~|'%';$;=$^='/'|$~;$;++;$\=$~|"'";$;++;$:.=++$;;$/=++$;; ++$\++;$_.= '#'|$~;$,=++$/;$_.="$\$^$\"";++$,;$_.='@'|'*'&~'!';$_.="$,$;$/$\"";$_. ++='!.'|$~. $~;$_.="$^$/$\$:$\"";$_.='@'|':'&~'*';$_.=$:;$_.=$^&'|';$_.=$".$\;$_.= ++"$~$~$~"| '!#+';++$.;$.++;`$_$:,>&$.`;
The (slightly) more readable results of Deparse
$~ = '`'; $_ = $: = $~ | '%'; $; = $^ = '/' | $~; ++$;; $\ = $~ | q[']; ++$;; $: .= ++$;; $/ = ++$;; ++$\; $_ .= '#' | $~; $, = ++$/; $_ .= qq[$\$^$"]; ++$,; $_ .= 'J'; $_ .= qq[$,$;$/$"]; $_ .= '!.' | $~ . $~; $_ .= qq[$^$/$\$:$"]; $_ .= 'P'; $_ .= $:; $_ .= $^ & '|'; $_ .= $" . $\; $_ .= "$~$~$~" | '!#+'; ++$.; ++$.; `$_$:,>&$.`;
-- Dave

Replies are listed 'Best First'.
Re: How in the heck?
by clintp (Curate) on Mar 17, 2001 at 07:25 UTC
    Since I spoiled Abigail's JAPH in Usenet just before YAPC::NA last year I really hate to spoil a JAPH. The big secret (there's no print!) is in this line:
    `$_$:,>&$.`;
    Alter that line so you print it with qq{`$_$:,>&$.`}; The rest is just encoding of the JAPH. And other details.
Re: How in the heck?
by chipmunk (Parson) on Mar 17, 2001 at 10:05 UTC
    Heh, this JAPH is inspiring a lot of discussion this time around. :)

    The challenge behind this obfuscation was to write a JAPH that contained no letters, digits, parens, brackets, braces, or whitespace (other than the newlines).

     

    Minor Spoiler

    None of the variables are being used for their special purposes. For example, $~ and $^ are both used with formats, but there are no formats in this code. The JAPH would work just as well with alphabetic variable names, except that it wouldn't meet the challenge that way, of course. :)

    By the way, all of the variables in this JAPH are interchangeable, except for one... Which variable could not have been used anywhere else in this obfuscation?

        None of the variables are being used for their special purposes.

      Thank you so muh chipmunk, as usual you're very helpful, ++.
      The problem I had was my attempt at seeing how the variables special meanings were being used, and reading | as || (bit-wise OR vs. logial OR).

      Thank you everybody for your help, I now "get it", at least a bit more :)

      -- Dave
Re: How in the heck?
by yakko (Friar) on Mar 17, 2001 at 07:14 UTC
    All those weird variables can be demystified via perlvar. I'm on my way to doing the same thing myself now. :o)

    --
    Me spell chucker work grate. Need grandma chicken.

      When high tech doesn't work try low tech. The code:
      #!/opt/CAV1perl/bin/perl $~ = '`'; print "`A "; $_ = $: = $~ | '%'; print "B $_\n"; $; = $^ = '/' | $~; print "C $;\n"; ++$;; print "D $;\n"; $\ = $~ | q[']; print "E $\\n"; ++$;; print "F $;\n"; $: .= ++$;; print "G $:\n"; $/ = ++$;; #print "H $\\n"; ++$\; print "I $\\n"; $_ .= '#' | $~; print "J $_\n"; $, = ++$/; print "K $,\n"; $_ .= '#' | $~; print "J $_\n"; $, = ++$/; print "K $,\n"; $_ .= qq[$\$^$"]; print "L $_\n"; ++$,; print "M $,\n"; $_ .= 'N'; print "P $_\n"; $_ .= qq[$,$;$/$"]; print "Q $_\n"; $_ .= '!.' | $~ . $~; print "R $_\n"; $_ .= qq[$^$/$\$:$"]; print "S $_\n"; $_ .= 'P'; print "T $_\n"; $_ .= $:; print "U $_\n"; $_ .= $^ & '|'; print "V $_\n"; $_ .= $" . $\; print "W $_\n"; $_ .= "$~$~$~" | '!#+'; print "X $_\n"; ++$.; print "Y $.\n"; ++$.; print "Z $.\n"; `$_$:,>&$.`; print "0 $_ AND $: , >& $.\n";
      Produces:
      perl t.pl `A B e C o D p E g gF q gG er gI h hJ ec hK t hL echo hM u hP echo N hQ echo Nust hR echo Nust an hS echo Nust another hT echo Nust another P hU echo Nust another Per hV echo Nust another Perl hW echo Nust another Perl h hX echo Nust another Perl hack hY 1 hZ 2 hNust another Perl hacker, 0 echo Nust another Perl hack AND er , >& 2
      Obviously not perfect but you can figure out what they did.