First off, it sounds like you should simply create a file to save these settings in. That is the best way to ensure that the settings are persistant. Then you simply have any of your subsequent scripts import the data. You could even still use the $ENV variables method.
For example, say that this was your settings file. ".settings"
-
$ENV{RCS_ROOR} = "your value here";
-
Then all scripts that needed this value could simply import it by doing an eval or require. Then simply access the data using the environment variable.
-
require ".settings";
-
-
print "$ENV{RCS_ROOR}";
-
If you do not need persistance, then making a simple assignment like in Kevin's example would work fine.
Concerning why setenv and export do not work. This is something that I've attempted before and eventually abandoned as a bad approach. Basically, my understanding is that setenv and export are something that is specific to the shell environment thatyou are using, whether it's tsh or bash, etc. You could try to do a system("bash export foo='bar'") call, but that would only last for that one statement. The only way to effect all subsequent shell environments is to add the export call to the .bashrc or .tcshrc start routine. And even then, that's not going to effect any shell environments that are already spawned.
Anyway, the moral of the story is to not rely on the environment that you're running perl under to set configuration data for other perl scripts. Instead create a configuration directory or file that all the scripts can share. Or if you simply need it for one session, use the method that Kevin suggests.
- Miller