I have one script that uses global variables - scalars, arrays, and hashes - declared 
with "use qw(...)". 

The script requires a configuration file in which these variables are assigned values 
and which also contains a few subroutines. 

At some point in the script, I want to switch to a different configuration file, use 
its variable values and the subroutines defined 
therein; then I want to switch back to the original configuration file. I thought of 
doing alternate require-s for this purpose, i.e. to first 
require one configuration file, then the second, and then again the first: 

1) mainscript.cgi
use vars qw($this $that);
require ("firstsetupfile.cgi");
print &create_code; # values and routine from first setup file
require ("secondsetupfile.cgi");
print &create_code;# do the same with second configuration file
require ("firstsetupfile.cgi"); # switch back
....
print "$this\n"; # should print "somevalue"

2) firstsetupfile.cgi
my $this = "somevalue";
my $that = "othervalue";
....
sub create_code {
my $output;
$output = "$this and $that";
return ($output);
}

3) secondsetupfile.cgi
my $this = "a completely different value";
my $that = "yet another value";
....
sub create_code {
my $output;
$output = "$this or $that or something else";
return ($output);
}

I've already noticed that arrays and hashes behave differently in the process: arrays 
apparently have to be undef-d, or otherwise, the 
new values are just added to the existing ones and don't replace them. With hashes, 
however, I don't have to undef; I don't really 
understand why. 

But apart from this, the approach only works for the first switch, meaning I can 
switch from firstsetupfile.cgi to secondsetupfile.cgi, 
but not back. 

Any suggestions? If there's a better way to do this, other than using require's, I'd 
be more than glad to learn of it. 

Best regards, 

Birgit Kellner


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

Reply via email to