in reply to Confusion about BEGIN block
I thought that everything in the BEGIN block is parsed firstNo, there's nothing special about when BEGIN blocks are parsed/compiled. The difference is that they are run immediately after, whereas code not in a special block is run only once the entire unit is finished compiling.
In some of the examples in this thread, there is an additional oddity that BEGIN blocks expose. Normally lexical variables are only available while in scope; that is, they are treated as if they are created when the scope is entered (at runtime) and destroyed when the scope is left. The exception is that prior to entering the scope for the first time, they already exist, and can be modified in a BEGIN block. Someday dave_the_m will document this :)
|
|---|