Michael G Schwern <[EMAIL PROTECTED]> writes:

> On Mon, Jan 14, 2002 at 04:16:49PM +0000, Piers Cawley wrote:
>> Michael G Schwern <[EMAIL PROTECTED]> writes:
>> 
>> > On Mon, Jan 14, 2002 at 10:23:46AM +0000, Piers Cawley wrote:
>> >> Um... You're wrong. If you do need 'startup time' initialization then
>> >> you should do it in an INIT block. If I may quote from the
>> >> documentation:
>> >
>> > Like it or not, people put lots of init code into BEGIN blocks, if
>> > nothing else for backwards compatiblity with 5.005.  perlcc has to
>> > compile real world programs.
>> 
>> Deferring BEGIN blocks 'til runtime will break rather more realworld
>> program than it fixes I think.
>
> Where is deferring involved?

Err... it goes like this:

<compile phase, includes BEGIN blocks and any modules that get 'use'd
by the main program>
<CHECK phase>
<INIT phase>
<Runtime>
<END>

The compiled file gets dumped out at CHECK time as I think we said
before. What you propose is to defer BEGIN processing to after the
CHECK phase. So, how do you decide whether 

BEGIN {
    push @INC, 'bibble';
}

gets evaluated at compile time (which it should because it has far
reaching effects about where stuff gets included from during
compilation), or if it gets evaluated at runtime. Admittedly, this one
is rather straightforward.

Now, consider something that does:

    package Package;
    use base 'Parent';

    # Parent implements 'some_method'
    BEGIN {
        Package->some_method 
    }

    CHECK {
        *Package::some_method = sub { ... }
    }

If what you propose comes to pass then running the result of 'perlcc
-o foo foo.pl' is going to be different from just running the script.

Yes, I know I'm picking an edge case, but actually distinguishing
between BEGIN blocks that should be evaluated at compile time and
those that should be evaluated at INIT time requires you to solve the
halting problem. Again.

Meanwhile we *do* have INIT blocks will do what you want without doing
the impossible. (Well, admittedly, educating programmers might well be
nearly impossible too, but dammit the behaviour of BEGIN blocks has
been *documented* since before there was a Perl compiler. And the
behaviour of INIT and CHECK blocks have also been clearly documented
since they were interested.

This really is a case of 'READ THE FSCKING MANUAL'.

-- 
Piers

   "It is a truth universally acknowledged that a language in
    possession of a rich syntax must be in need of a rewrite."
         -- Jane Austen?

Reply via email to