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!!!


In reply to mod_perl - local vs my... by smullis

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.