BEGIN { s .$.n.; END { s .$.a.; CHECK { s .$.o.; INIT { s .$.h.; BEGIN { s .$.a.; END { s .$.c.; CHECK { s .$.t.; INIT { s .$. .; BEGIN { s .$. .; END { s .$.k.; CHECK { s .$.h.; INIT { s .$.l.; BEGIN { s .$.t.; END { s .$.e.; CHECK { s .$.e.; INIT { s .$.r.; BEGIN { s .$.s.; END { s .$.r.; CHECK { s .$.r.; INIT { s .$.e.; BEGIN { s .$.u.; END { s.$.\n.; CHECK { s .$. .; INIT { s .$.P.; BEGIN { s .$.J.; }}}print}}}}}}}}}}}}}}}}}}}}}}
   MeowChow                                   
               s aamecha.s a..a\u$&owag.print

Replies are listed 'Best First'.
Re: The BEGINning of the END
by tachyon (Chancellor) on Jul 05, 2001 at 17:13 UTC

    An interesting demonstration of execution order. To understand this first you need to understand this simple code:

    s/$/J/; s/$/u/; print;

    This code reads substitute 'J' for the null string at the end of $_; sub 'u' for the null string at the end of $_; print $_;

    As you may know you can use virtually any charachter as a delimiter for s/// - In this case we have s... OK so thats how we get JAPH into $_ for print.

    The BEGIN CHECK INIT and END blocks are special blocks that execute in that order. BEGIN blocks execute in FIFO order at compile time CHECK blocks execute in LIFO order during the Code Generation Phase, INIT blocks execute in FIFO order at the beginning of runtime, and finally END blocks execute in LIFO order at the end of runtime .

    So what's all this LIFO and FIFO. That's Last In First Out and First In First Out if you are suffering from jargon aphasia.

    OK almost there so the BEGIN blocks execute first in FIFO. So what is the 'first' in. No it is not the *upper most* but actually the *innermost*. You can see this behaviour here:

    {print 'J'; {print 'u'; {print 's'; {print 't'; }}}} BEGIN{print 'J'; BEGIN{print 'u'; BEGIN{print 's'; BEGIN{print 't'; }} +}}

    What you can see it that with the embedded block structure we process the prints in L->R order. However with the embedded BEGIN blocks the FIRST block that the parser can completely parse is the innermost so this is 'first in'. Once the innermost is done the next innermost can be parsed, etc. Thus the FIFO blocks execute in bottom to top order in this JAPH and the LIFO blocks execute top to bottom. So now you just read them in order: BEGIN blocks bottom to top; CHECK blocks top to bottom; INIT blocks bottom to top and END blocks top to bottom.

    So the net result is we sub in JAPH to $_ and print it. Nice demonstration of many of the salient features of these command blocks. Oh and clever to....

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n\w+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Re: The BEGINning of the END
by VSarkiss (Monsignor) on Jul 05, 2001 at 21:54 UTC
    A quick note: CHECK blocks were introduced in 5.6. On my 5.005_02 installation, this generates an error. Strictly speaking, you should run it with perl -M5.6 ... Very nicely done, though. Doesn't even look like Perl....
Re: The BEGINning of the END
by Prince99 (Scribe) on Jul 05, 2001 at 21:05 UTC
    Very Nice. Did notice that you get a couple of errors when run without -w and use strict;
    Use of uninitialized value in substitution (s///) at 5.pl line 28.
    Use of uninitialized value in substitution (s///) at 5.pl line 28.
    Otherwise a very nice JAPH.

    Update:Does Obfuscated code require -w and use strict;?
    Prince99

    Too Much is never enough...
      As with golf, it's of course a greater achievement to have a japh/obfu run cleanly under strict and/or -w, but such code doesn't require strict or -w in the sense that production code does. It's just for fun, so the only rules are those that we create.
         MeowChow                                   
                     s aamecha.s a..a\u$&owag.print
Re: The BEGINning of the END
by MZSanford (Curate) on Jul 06, 2001 at 14:23 UTC
    I believe this is the maening of ObFu. This uses perl shortcuts and builtins to provide something that is completly illegible. I tip my hat sir.
    may the foo be with you