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

Whatever you are trying to do, it sounds wrong. You are abusing the normal use of modules. Write a sub in the module and have the main script call it.


Perl is environmentally friendly - it saves trees

Replies are listed 'Best First'.
Re^4: when is a perl module executed?
by ketaki (Acolyte) on Jul 17, 2008 at 03:33 UTC
    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?
      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