Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
There's a bit more to it...

In mod_perl, scripts are loaded as subroutines. So all the scripts form a part of one larger, main script. That sounds somewhat dangerous, and it is.

You can imagine the big source to look a bit like:

sub script1 { # contents of script file 1 inserted here my $x; # this is problematic in mod_perl... sub foo { # ... } foo(); } sub script2 { # contents of script file 2 inserted here sub foo { # ... } foo(); }

Nested subs are somewhat problematic in Perl, in that they form a closure around the data the first time the outer sub is called. If there's a lexical variable ($x) that is used inside an inner sub, then the next time the lexical $x will see a different variable, but the inner sub will use the same variable it saw in the first invocation of the outer sub. So the nested sub foo will, after the first time, see a different $x than the top level sub script1 does. That's a major PITA, and, IMHO, not how it is supposed to be. But P5P seems reluctant to "fix" it, probably because it's very hard to fix (and to get it right).

Lesson to be learned: don't use top level lexicals in mod_perl. Use globals instead, but you best somehow restrict the effect of the scope to the script... I think local (and our or use vars, for strict) ought to do.

A second consequence is that if you edit a script, then in CGI it'll immediately be picked up by the webserver, but in mod_perl you have either restart the server, or find some other way to force it to reload the script from file — I think there are a few tricks to make that happen.


In reply to Re^2: Wht is the difference between CGI and Mod_Perl by bart
in thread Wht is the difference between CGI and Mod_Perl by veeruch

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-04-24 11:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found