Markus Laire wrote in perl.perl6.compiler : >> my $use_debug_mode = BEGIN { %*ENV{DEBUGME} ?? 1 :: 0 }; > > According to S04 you'd use INIT block for that. INIT is run at run time, > ASAP. But BEGIN is run at compile time, ASAP.
Fair enough, makes sense. As long as BEGIN and CHECK blocks are run when you evaluate code at run-time (which is not the case in perl 5 for CHECK blocks currently) > My example code: > use v6; > my $compile_begin_time = BEGIN { time() } > my $compile_end_time = CHECK { time() } > my $run_begin_time = INIT { time() } > my %compile_time_environment = BEGIN { %*ENV } > my %run_time_environment = INIT { %*ENV } > > > (this list from http://dev.perl.org/perl6/synopsis/S04.html ) > > BEGIN {...}* at compile time, ASAP > CHECK {...}* at compile time, ALAP > INIT {...}* at run time, ASAP > END {...} at run time, ALAP > FIRST {...}* at first block entry time > ENTER {...}* at every block entry time > LEAVE {...} at every block exit time > KEEP {...} at every successful block exit > UNDO {...} at every unsuccessful block exit > NEXT {...} at loop continuation time > LAST {...} at loop termination time > PRE {...} assert precondition at every block entry > POST {...} assert postcondition at every block exit > CATCH {...} catch exceptions > CONTROL {...} catch control exceptions