On Wed, 16 Oct 2002, nemesis wrote: > If I preload Page.pm and have a BEGIN {} block in it that loads the > template file into a variable for use within the module, would this > BEGIN block get run when the module was use'ed, some other time, or not > at all?
Right, this is where I explain what BEGIN time is. BEGIN time is the time when perl does it's initial sweep over the module as it's working out what's actually there. It's the bit where perl looks for syntax errors in your code etc. Blocks that you define with BEGIN, or are inherently BEGIN (like all "use" statements) get called straight away...before you even check the code below. "use" statements happen at BEGIN time as you often need to load the code that you are using to prevent compile time problems in the rest of the code that you are parsing after the use statement. So, when you "use Page;" then, as a use statement it switches files and starts running over the code in Page.pm. All this happens in BEGIN time for your original code, but there's a separate BEGIN time stage and run-time-time stage for Page.pm which all happens as that code is parsed (BEGIN time) and then executed (run-time-time) before the rest of your original code is run. *phew* Back to the original problem. You want to load Page.pm or whatever in your startup.pl (or again, whereever) and have it load in the file once before forking so that a) it doesn't have to load it every time and b) you have one copy in memory. So the answer is yes, you could defined a BEGIN block in Page.pm that loaded the page and stuck it in a global variable and everything would run fine, but you don't have to and it's probably bad form. Instead, you should just stick this code in the main body of your module as all this code will be executed in the BEGIN time of startup.pl Make sense? Mark. (Please note that this is a broad description and may fudge over some details in an attempt at clarity.) -- s'' Mark Fowler London.pm Bath.pm http://www.twoshortplanks.com/ [EMAIL PROTECTED] ';use Term'Cap;$t=Tgetent Term'Cap{};print$t->Tputs(cl);for$w(split/ +/ ){for(0..30){$|=print$t->Tgoto(cm,$_,$y)." $w";select$k,$k,$k,.03}$y+=2}