tmaciak has asked for the wisdom of the Perl Monks concerning the following question:
I am seeking wisdom on how one would go about defining global variables for a cgi application that get their values from a database. These variables will change periodically (whenever the database values change) and they are used throughout an entire application.
The problem I am running into is that if I wait until a run mode to grab the data from the db then I must declare the global variables without a value at the top of the program. The data will usually be there for the first run mode but by the time we goto the second (or a different) run mode, then the data is blanked out again because of the global declarations with no value.
I have been able to call a seperate function below the setup function and manually define these global variables here, but I have been unsuccessful on calling it up with $self to attach to the db handle. If I could get this to work then it would probably be golden.
Thanks for any advice/help.
minimal code sample:##################################################### our variable1 = 2003; our variable2 = 2004; sub setup{ my $self=shift; $self->start_mode('start'); $self->mode_param('rm'); my $dbh=getDbConnection("universe"); $self->param('dbh'=>$dbh); $self->run_modes( start=>\&showstart, search=>\&genSearchPage, show_type_1=>\&genShow1, show_type_2=>\&genShow2, calculate=>\&genCalculator, iamge=>\&generateImage ) } sub showstart { use variable1 here; use variable2 here; } sub genSearchPage { use variable1 here; use variable2 here; } sub genShow1 { use variable1 here; use variable2 here; } ... etc. etc.
As you can see, right now the variable1 and variable2 are hard coded, but I want to be able to get their values from a database and then have all the subs be able to access those variables with the values from the database. Problem is that I dont connect to the database until I am in setup, so unless I manually connect again to the database at the top, I cant get a connection to the db before I run setup.
Edited by footpad, 19 December 2003: Revised HTML formatting and added <code> tags.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: CGI Application and global variables (from a database)
by jdtoronto (Prior) on Dec 19, 2003 at 17:02 UTC | |
by tmaciak (Initiate) on Dec 19, 2003 at 18:35 UTC | |
|
Re: CGI Application and global variables (from a database)
by davido (Cardinal) on Dec 19, 2003 at 16:54 UTC | |
|
Re: CGI Application and global variables (from a database)
by Joost (Canon) on Dec 19, 2003 at 16:46 UTC | |
|
Re: CGI Application and global variables (from a database)
by freddo411 (Chaplain) on Dec 19, 2003 at 18:20 UTC | |
|
Re: CGI Application and global variables (from a database)
by mpeppler (Vicar) on Dec 19, 2003 at 16:46 UTC | |
|
Re: CGI Application and global variables (from a database)
by swngnmonk (Pilgrim) on Dec 19, 2003 at 18:00 UTC |