Wednesday, August 6, 2008

Perl CGI cached parameters.

An intern at work today ran into a problem modifying a perl cgi script. It looked something like this


my $cgi = new CGI;
$cgi->param('foo');


The problem was this value appeared to be cached. Once I accesed the page with http://server/page?foo=bar it would remember bar no matter what I changed the value to.

First I thought it was a cache issue. So we changed the code to output a timestamp. On each page load we would see the time increment but the variable was still cached somehow.

We finally found out that putting the new CGI call inside a function made sure we got a new one each time.

So what happened? I'm not really sure, I'm guessing scope of the perl code is global per apache process? Is this configurable somehow?

Well if anyone knows please add a comment because i this point I'm still baffled by it.

No comments: