On Wed, 2004-04-14 at 13:07, Jeremy Silva wrote:
> The following code will cache the CGI
> parameters with Mod_perl.
It will cache them without mod_perl too, although you won't see it
because your CGI will exit after each request. Your sub
increment_counter() is a closure because it uses the $cgi (and $counter)
variable that is declared outside of it's scope. You have to pass $cgi
to every sub that you want to use it in.
Here's a cleaned up version of your code:
# counter.pl
use strict;
use warnings;
use CGI;
use Counter;
my $cgi = CGI->new();
Counter::run($cgi);
# Counter.pm
sub run {
my $cgi = shift;
print "Content-type: text/plain\r\n\r\n";
print "HERE";
my $counter = 0;
for ( 1 .. 5 ) { increment_counter(\$counter, $cgi); }
}
sub increment_counter {
my ($counter_ref, $cgi) = @_;
${$counter}++;
my $str = $cgi->param("name");
print "Name=$str Counter is equal to $counter !\r\n";
}
1;
- Perrin
--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html