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 |