JAWS (
[email protected]) wrote:
: I need to use the csh source command or anything equivalent form a perl
: script but i can't access the source command because the shell fired by
: perl is sh.
So use that shell to fire up csh to source the file.
Ideally, i also need to be able to use the new environment
: variables in the rest of my perl program...
The truth comes out, it's a faq, you can't do what you want directly (on
unix like systems).
o You can define the vars before you run perl. This is by far the easiest
in the long run.
$ . vars.sh
$ perl my_script.pl
o From within perl you check for the variables, and if they are not set
then use system to run a short shell script that a) sets the variables and
then b) (re)invokes your perl script
# just an illustration !!
if not $ENV{FOOBAR}
{ exit system(". stuff; export FOOBAR=1; perl $0 @ARGV");
}
o You can ask the shell script to print the variables and then parse the
output
# just an illustration
#!/bin/sh
# vars.sh
MY_VAR="set its value";
#!perl
$values = `. vars.sh; echo MY_VAR=$MY_VAR`;
my ($my_var)=$values=~m/MY_VAR=(.*)/;
o You can parse the shell script yourself, it's easy for simply X=Y
assignments.
#!perl
# YOU MUST TRUST THE CONFIG FILE (of course you do or you couldn't
# source it in the shell script either)
use strict;
my ($MY_VAR);
{ local @ARGV=qw(vars.sh);
# local $SIG{__WARN__}=sub{1}; # do we want to see warnings.
map {eval "\$$_"} grep {/^\w+=/}<>;
}
o There are probably modules that will do variations of the above to pull
configurations variables out of configuration files.