in reply to Re^7: Making a variable in a sub retain its value between calls
in thread Making a variable in a sub retain its value between calls
I'm curious. When do you need to use INITs to delay execution after all BEGIN blocks in scripts?
The point is that I don't have to even think about it. This is all very simple: I have a script, I have various bits of initialization code that need to be executed before run time scattered throughout; so I put them INIT blocks, without having to give a second's thought to what possible conflict any one of these INIT blocks may have with some BEGIN block later in the code.
The point of using INIT blocks to solve the static variable initialization problem is to give the programmer the flexibility to arrange code as desired; otherwise it would have been sufficient to stick all subs with static variables at the top of the file. If one puts this initialization code in BEGIN blocks now one goes back to having to worry about the position of these initalization BEGIN blocks relative to other BEGIN blocks (including implicit ones in use statements) in the file, which makes no sense to me.
the lowliest monk
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^9: Making a variable in a sub retain its value between calls
by ikegami (Patriarch) on Apr 19, 2005 at 04:49 UTC | |
by tlm (Prior) on Apr 19, 2005 at 05:46 UTC | |
by ikegami (Patriarch) on Apr 19, 2005 at 19:09 UTC | |
by ihb (Deacon) on Apr 19, 2005 at 16:08 UTC | |
by TimToady (Parson) on Apr 19, 2005 at 16:28 UTC |