in reply to Re: What can we assume in a BEGIN block ?
in thread What can we assume in a BEGIN block ?

Howdy!

That would be spot on!

The call to _initialize occurs at compile time, but the initialization part of the "our" statement occurs at run time.

yours,
Michael
  • Comment on Re^2: What can we assume in a BEGIN block ?

Replies are listed 'Best First'.
Re^3: What can we assume in a BEGIN block ?
by leriksen (Curate) on Oct 04, 2004 at 11:34 UTC
    OK, so now I know I really dont get it.

    What variable got incremented at compile time ? If the "our $initialised" doesnt happen till run-time, what did we increment during the BEGIN?

    use brain;

      The variable $initialized was declared by the my $initialized. This made it known the parser so when the source code farther down saw it, it incremented the variable. At the time, the value was still undefined because while the variable had been declared, the = 0; hadn't run yet. So now $variable = 1 after the BEGIN. Now that the file is finished being parsed, execution starts at the top so now you run $initialized = 0;.

      $variable := undef -> 1 -> 0