Quoth (e-mail address removed) (jm):
When in a hurry explaining yourself clearly will *definitely* result in
quicker and more useful answers (if any) than being vague.
What I meant was:
system ('export PATH=/mypath:$PATH');
system ('. /mypath/myenvironment some_argc');
The problem is that I am using DBI and I have to be in a certain
environment to use it. I can't just call DBI. I have to set several
variables in the system (export myvar=myvalue) etc. and finally be in
a production environment before I can rund the DBI stuff in the Perl
script.
Right, that can't be done, as it stands. system forks a shell; this
shell cannot affect the working environment of the perl process.
You can change your environment variables yourself using the %ENV hash,
so for instance you can do
$ENV{PATH} = "/mypath:$ENV{PATH}";
.. You may find if this is for a DBD module that you need to do this in a
BEGIN block: certainly, I've found that with DBD::Sybase before.
Alternatively, if it is for some reason inconvenient to re-write the
shell script setting up the environment in Perl, you can wrap the perl
script in a shell script:
Move 'script' to 'script.pl'
Create a new file 'script' like
#!/bin/sh
export PATH="/mypath:$PATH"
.. /mypath/myenvironment some_argc
perl /path/to/script.pl
A third way would be to do something like
/(.*?)=(.*)$/ and $ENV{$1} = $2 for qx{
export PATH=...
. /mypath/...
env
};
if you can be sure nothing in your environment has a newline in it.
Ben