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

it doesnt seem so. i added a statement which is written below into an already existing module which i had written. the line which i added is
print "aaaaaaaaaaaaaaaaaa";
and it doesnt print that text (aaaaaaaaaaaa) when the perl file is executed. Is it becoz im executing the perl file on the webserver and seeing the output on the browser on the internet. the perl file is a cgi file. the rest of the program runs. only this text (aaaaaaaaaaaaaaaaaaaaa) is not being printed anywhere.

Replies are listed 'Best First'.
Re^3: when is a perl module executed?
by chromatic (Archbishop) on Jul 17, 2008 at 05:00 UTC
    and it doesnt print that text (aaaaaaaaaaaa) when the perl file is executed.

    If it doesn't, then print is broken in Perl and no one has noticed all these years. print is probably not broken in Perl.

    It's more likely that that (unbuffered) print occurs before you've finished printing HTTP headers to the browser, so it's getting lost somewhere that you don't see it. Run your program from the command line instead to see that, indeed, print works in Perl as it has worked for 20 years.

Re^3: when is a perl module executed?
by GrandFather (Saint) on Jul 17, 2008 at 03:30 UTC

    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
      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
Re^3: when is a perl module executed?
by Anonymous Monk on Jul 17, 2008 at 05:13 UTC
    You didn't pay off the Executioner :p
A reply falls below the community's threshold of quality. You may see it by logging in.