[Israel.pm] Setting environment variables in PERL

Offer Kaye offer.kaye at gmail.com
Mon Nov 22 12:21:23 PST 2004

On Mon, 22 Nov 2004 18:31:55 +0200, Prager, Mark wrote:
> Hi All -
> I want to try and set a new environment variable within one perl script and use it within 
> another.
> I have looked up various sources - yet when I try - it fails -
> I do:
> Use Env;
> ...
> $ENV('NEW_ENV_VARIABLE') = $my_value;
> but it fails - any ideas ?

As someone else said, setting an environment variable within script
"A" will only affect another script "B" if you run it from within
script "A" (i.e. "B" is a "son" of "A"). This is true for all
Unix/Linux processes, not just Perl.
Specifically for your code, get rid of the "use Env;" line (you don't
seem to be using it) and change the parenthesis to braces - you're
adding/changing an element to/in a hash:
$ENV{'NEW_ENV_VARIABLE'} = $my_value;

I wonder what $hash('new key') does. What kind of error message do you
get? Should be a compilation error...

Offer Kaye

More information about the Perl mailing list