Autrijus Tang wrote in perl.perl6.compiler : > Consider this program, example.p6: > > use v6; > my $var = BEGIN { say "I'm compiling, man"; time() } > say "Compiled at { time() - $var } seconds ago!"; > > Is this behaviour correct? > > % pugscc --parrot example.p6 > I'm compiling, man > % sleep 60 > % parrot example.pmc > Compiled at 60 seconds ago!
It looks not correct to my perl 5 trained eyes. BEGIN is designed to let things run as early as possible, mostly for Perl programs to discover things about the environment they're running in. That's a different environment than the environment they were compiled in. For example : my $use_debug_mode = BEGIN { %*ENV{DEBUGME} ?? 1 :: 0 }; On the other hand there are CHECK blocks too.