I'm rethinking the basic approach to a database managing script I have and 
would need some advice about how to rewrite it into some modules, cgi 
scripts that use them and smaller files which are "require"-d and whose 
variables I need available in the modules/scripts.

The setup I have now is basically as follows:
There's a main script db.cgi which parses form input and contains subs for 
adding, deleting, modifying records as well as search routines and sets 
global variables like script path and so forth.
A secondary script html.pl contains all code needed to build html.

The script accesses several (flatfile) databases.
Each of these has a configuration file database.cfg which specifies 
variables peculiar to that individual database, like its name, field names 
or other customizable settings like whether search results should be bold, 
and the name of a file databaseconfig.pl which builds html specific to that 
database (search forms, display of search results).

So, conceptually speaking, I have a two-direction process:
- some script components access common subs stored in modules
- the modules, or commonly accessed scripts, need to parse configuration 
files to get individual database information

My approach would be this:
- strip db.cgi down to that part which parses form input and calls subs for 
adding, deleting, modifying as well as html display depending on form input 
values.
- take all general subs out of db.cgi and store them in a module 
DATABASEMANAGER.pm
- rewrite html.pl into a module DATABASEHTML.pm

I guess I'd have to declare all variables to be exported - i.e. global 
variables like the script path that I want accessible in all script 
components - in the modules with "use vars" first and then specify them in 
@EXPORT, @EXPORT-OK or %EXPORT_TAGS. Then they would be imported into 
wherever I need them with "use DATABASEMANAGER" etc. This much I 
understood.

What I don't yet understand is the other direction: How do I make 
individual configuration variables, taken from database.cfg, available in 
the modules or db.cgi? I guess that would be a job for "require", but am 
not sure.

Right now, the database name is passed through the query string as value of 
"db" (/mypath/db.cgi?db=database).
Then database.cfg is "require"-d in db.cgi.

So to make values defined in database.cfg, like $db_file_name, available in 
db.cgi would be the following:

#!usr/bin/perl

use strict;
use vars qw ($db_setup $db_file_name %in);
use CGI qw(:standard);
my $in = new CGI;
%in = &parse_form;
if ($in{'db'}) { $db_setup = $in{'db'};} #

eval {
...
        require "$db_setup.cfg";
}
...
#now I can use $db_file_name

Or could/should I use "our" instead of "use vars" for (a) initializing 
variables which will then be filled be requiring $db_setup.cfg and/or (b) 
initializing variables which will then be exported from a module?

Any thoughts or words of advice would be greatly appreciated.

Birgit Kellner









-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to