Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-24 21:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found