-I'll try to use, in my Perl scripts, lexical variables instead of global
variables, so that I'm sure the used memory can be resued for later
requests
(global variables, on the other hand, stick in memory, due to mod perl
way
of operating)
Not really. In terms of memory, there's no difference. The reason
you should use lexicals is that it's a better programming style.
There's really no difference in the way globals behave under mod_perl.
You just don't notice it under CGI because the process quits right
after the request has been served.
Here, I'm getting confused.
Let's imagine I'm running the following script though ModPerl::PerlRun or
ModPerl::Registry:
use strict;
package mypack;
my $lexical;
our $global;
print lexical: ' . $lexical. ' # global: ' . $global;
$lexical= 2007;
$global = 2007;
This script would print:
lexical: # global:
the first time it is run
and then:
lexical: # global: 2007
So, this clearly shows that the global variables sticks in memory, while the
lexical one doesn't.
So, I would imagine that after the script is run, space used by the lexical
variable would be freed up.
Am I wrong?