|laziness, impatience, and hubris
Re^5: Making a variable in a sub retain its value between callsby ihb (Deacon)
|on Apr 19, 2005 at 00:24 UTC
I'm talking about program run-time, not any file's run-time. If you have a module Foo that uses INIT you'll get a "Too late to run INIT block" warning if you require Foo during program run-time. E.g. you have
That won't execute like one would hope. By using INIT to initialize variables to constants you impose a completely unnecessary constraint on your module. No module that uses your Foo can be loaded at program run-time, meaning you can't ever use Foo, directly or indirectly, in any module that is dynamically loaded (like plugin modules). That's quite a serious limitation.
There's absolutely no reason, in general, for the initialization of the typical static variable to not happen at compile-time.
See perltoc if you don't know which perldoc to read!