in reply to Re^2: What can we assume in a BEGIN block ?
in thread What can we assume in a BEGIN block ?
I think you're reading
our $foo = 1; BEGIN {...}
as: allocate some memory and initialise it to 1 and you expect it to happen at parse/compile time but you should think of it as just a shorthand for
so the memory is allocated at compile time but the initialisation happens at runtime, which will be after all the BEGIN blocks have run.our $foo; $foo = 1; BEGIN {...}
It might seem like a good idea to initialise $foo to 1 at the same time as allocating the space but then you run into problems like
our $foo=sub_which_hasnt_been_compiled_yet();
|
|---|