On Fri, Mar 25, 2005 at 08:32:13AM -0000, Rafael Garcia-Suarez wrote: > 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.
The pugs behaviour is consistent with Perl 5's byte compiler/ByteLoader: $ cat sleeper my $var; BEGIN { print "I'm compiling, man\n"; $var = time(); }; print "Compiled at @{[ time() - $var ]} seconds ago!\n"; __END__ $ ~/Reference/5.8.1/bin/perl5.8.1-32 ~/Reference/5.8.1/bin/perlcc5.8.1 -B sleeper $ sleep 60 $ ~/Reference/5.8.1/bin/perl5.8.1-32 a.out Compiled at 65 seconds ago! If anyone wants to play with it, please note that the Perl 5 ByteLoader is "experimental", not always reliable by 5.8.1, definitely not efficient, and I think inadvertently broken from 5.8.3 or so onwards. Bug reports on it are interesting, but fixing it isn't a priority. (Limited volunteer resources, hard problem, and plenty of other things that can be done that are a better use of time and enthusiasm) Nicholas Clark