in reply to Re^3: when is a perl module executed?
in thread when is a perl module executed?

you mean generally it is done like this that the code in sub is executed when the sub is called for from the perl file right?

Replies are listed 'Best First'.
Re^5: when is a perl module executed?
by massa (Hermit) on Jul 17, 2008 at 10:51 UTC
    You have a series of problems:
    1. the text outside functions in a module is executed at BEGIN time and only once if you use the module; this is because
      use Module;
      is a special way of saying
      BEGIN { require Module; }
      and require only loads each module once (it checks on @INC to see if the modules wasn't already loaded.
    2. as you are under some CGI environment, some possibilities exist: the module was loaded before CGI (so STDOUT wasn't redirected to the browser yet), or you missed the first time you loaded the page and the module was already loaded by perl (and then you won't see it again, even if you reload the page, because the module is already loaded).
    3. You are yet to explain why you want to do this. Maybe if you explain, we can come up with alternatives for you.
    []s, HTH, Massa