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.# Foo.pm INIT { print 'Foo' } # foo.pl require Foo;
There's absolutely no reason, in general, for the initialization of the typical static variable to not happen at compile-time.
ihb
See perltoc if you don't know which perldoc to read!
In reply to Re^5: Making a variable in a sub retain its value between calls
by ihb
in thread Making a variable in a sub retain its value between calls
by crashtest
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |