http://www.perlmonks.org?node_id=406344

smullis has asked for the wisdom of the Perl Monks concerning the following question:

Hello all....

Help!

I have a mod_perl (v2) app that - among other things - reads a local config file based on the contents of an encrypted cookie value set by a frontend server. It all seems to work beautifully....

Except!

If I click stop / break the browser session while a page is loading then the subsequent requests seem to get themselves in a bit of a muddle (i.e. the results reflect the wrong config file).

After some reading here it seems that this code is the problem:

sub read_the_config() { open(CFG, "<$file") || log_error("Problem reading $file - $!"); while (<CFG>) { chomp; # remove newline s/\s+$//; # remove trailing space s/\s+/ /g; # collapse white spaces to ' ' next if /^ *\#/; # skip comment lines next if /^\s*$/; # skip empty lines if (/^ \S/) { # multiline options $lines[$#lines] .= $_; } else { push @lines, $_; } } close CFG; }

Are there any simple mod_perl recipes for ensuring that all variables are cleared on each subsequent page request?

Could it be as simple as using local within the function to force the variable to be undef when that block is left?

i.e.

sub read_the_config() { local $localfile = $file; open(CFG, "<$localfile") || log_error("Problem reading $file - $!"); while (<CFG>) { chomp; # remove newline s/\s+$//; # remove trailing space s/\s+/ /g; # collapse white spaces to ' ' next if /^ *\#/; # skip comment lines next if /^\s*$/; # skip empty lines if (/^ \S/) { # multiline options $lines[$#lines] .= $_; } else { push @lines, $_; } } close CFG; }

Or is there some other such Perl Magick I can employ...


Many thanks in advance for any pointers / tips / constructive criticism...

Cheers

SM

UPDATE:

Apologies - When originally writing this question I left out some of the code thinking (incorrectly it seems) that it would confuse the issue...

Here it is in full...

sub read_the_config($$$$) { my ($file, $def, $cfgref, $order) = @_; my @lines; open(CFG, "<$file") || log_error("Problem reading $file - $!"); while (<CFG>) { chomp; # remove newline s/\s+$//; # remove trailing space s/\s+/ /g; # collapse white spaces to ' ' next if /^ *\#/; # skip comment lines next if /^\s*$/; # skip empty lines next if /^TopTalker*/; if (/^ \S/) { # multiline options $lines[$#lines] .= $_; } else { push @lines, $_; } } close CFG; foreach (@lines) { do all sorts of groovy stuff....} }
I presume the suggestions of Ikegami are still relevant? i.e.:
... local *CFG; open(CFG, "<$file") || log_error("Problem reading $file - $!"); while (<CFG>) { ... return \@lines;

Cheers

SM

UPDATE 2:

After spending some time trying the solutions below I have had no luck. A Ctrl-f5 refresh (btw I have client side caching turned off and have set the relevnat Pragma: Nocache header vars) seems to make the mod_perl app randomly jump from one previously loaded config to another....

When I restart httpd it always works as expected.

Does anyone have any suggestions as to how I can force clearing all variables within the mod_perl app for subsequent request? I am using cookies for persistence but obviously I can set that each time the user instantiates the page...

....Help!!!