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

I have 5 scripts, each one is run in succession when a user clicks a submit button. Is there a way to have a global variable available to all the scripts between http process requests? -Lisa

Replies are listed 'Best First'.
Re: global variable between scripts
by sauoq (Abbot) on Nov 13, 2002 at 00:51 UTC

    Rather than a global variable, I think what you want is a value which persists but which may be differ between users. Since HTTP is a stateless protocol, you will need to maintain the state (or a pointer to it) on the client side. Generally that's done with cookies. Hidden form elements can sometimes be useful as well but only if you are already dynamically generating the form content.

    -sauoq
    "My two cents aren't worth a dime.";
    
Re: global variable between scripts
by valdez (Monsignor) on Nov 13, 2002 at 01:06 UTC
Re: global variable between scripts
by Anonymous Monk on Nov 13, 2002 at 04:45 UTC
    You probably want to use cookies, but just for variety, here are some more possibilities:

    You could process the pages with your script and insert the variable into the HTML as a hidden form field, but this leaves it open to manipulation. Another possible solution is to write the variable to a file linked to the user's IP address or a combination of any two of these: write the variable to a file linked to cookie data you set in the user's browser, etc...

    SpaceAce

Re: global variable between scripts
by broquaint (Abbot) on Nov 13, 2002 at 10:45 UTC
    And just for completeness there is Simon Cozen's Attribute::Persistent which allows for the persistence of variables with the greatest of ease. Here's some example code from the docs
    use Attribute::Persistent; my %hash :persistent; # Value retained between calls to the program. $hash{counter}++; # Explicitly provide a filename. my %hash2 :persistent(SessionTable);

    HTH

    _________
    broquaint