Begin at the BEGIN and go on till you come to the END: then stop.
In Perl we can run user defined code blocks at different stages when running a program.
- BEGIN blocks are run as soon as Perl finds them. If there is more than one block they get executed in the order they are found.
- CHECK blocks are run as soon as Perl finishes compiling. If there is more than one CHECK block they get executed in the reverse order they are found.
- INIT blocks are executed after CHECK blocks, and if more than one exists they get executed in the order they appear.
- END blocks get executed before the program finishs running, and no errors where found. If more than one END block is found they are executed in the reverse order they appear.
END { print "Twelve\n"; } BEGIN { print "One\n"; } CHECK { print "Six\n"; } INIT { print "Seven\n"; } BEGIN { print "Two\n"; } END { print "Eleven\n"; } CHECK { print "Five\n"; } INIT { print "Eight\n"; } BEGIN { print "Three\n"; } INIT { print "Nine\n"; } CHECK { print "Four\n"; } END { print "Ten\n"; }
When we run the script it prints someting like:
$ perl blocks.pl One Two Three Four Five Six Seven Eight Nine Ten Eleven Twelve
Playing with this I found that GitHub didn't highlight CHECK and INIT blocks. So I patched it.
You left out the new UNITCHECK block. From perldoc perlmod: