in reply to BEGIN initialization and memory

I believe it does make sense that an initialization routine (inside BEGIN) block actually keeps the variables hanging around, otherwise you wouldn't have initialized variables, would you?

Replies are listed 'Best First'.
Re: Re: BEGIN initialization and memory
by chromatic (Archbishop) on Jul 23, 2003 at 23:12 UTC

    What would you expect to happen here?

    BEGIN { my $x = 'foo'; }

    Outside of the block, would you expect to see a variable named $x? Would you expect it to have a value?

    In fact, it doesn't, because the normal lexical scoping rules apply. BEGIN isn't extra special magic in that variables leak out. It's just a normal block that happens to execute at a special time.

Re: Re: BEGIN initialization and memory
by bsb (Priest) on Jul 23, 2003 at 23:09 UTC
    Is the memory used for the code/ops/(?) of a BEGIN block released after it is executed? I'm thinking particularly of initialization code.

    I'm talking about the memory required for the compiled perl code of the BEGIN block itself.