my %BB_ENV = `/bin/sh . /usr/local/env.sh`;
Backticks (`STRING`) return a simple scalar. Assigning this to a hash gives you a single, very long key associated with an undefined value, and will throw a warning when you use warnings (You are using warnings, right?). In order to obtain a set of key-value pair, you need to process that string. Assuming an output like printenv, you might use a pair of splits, like
my %BB_ENV; for my $line (split /\n/, `/bin/sh . /usr/local/env.sh`) { my ($key,$value) = split /=/, $line, 2; $BB_ENV{$key} = $value; }
%ENV = { %ENV, %BB_ENV };
A pair of curly brackets gives you an anonymous hash reference, not a hash. A hash ref is a scalar - see perlreftut. You probably mean just a simple list assignment, which would use parentheses:
%ENV = ( %ENV, %BB_ENV );
though I would instead manually copy in values, key by key:
$ENV{$_} = $BB_ENV{$_} for keys %BB_ENV;
In any case, you should probably follow Anonymous Monk's links above for some other approaches to solving this issue.
In reply to Re: get environment variables from a bourne file
by kennethk
in thread get environment variables from a bourne file
by BradV
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |