Perl equivalent to Kornshell export command?

162 views Asked by At

I'm working on translating some kornshell to perl and was wondering if there is an equivalent in perl to export

1

There are 1 answers

2
Jonathan Leffler On BEST ANSWER

It's very straight-forward. The %ENV hash contains the values of the environment variables keyed by environment variable name. You can set or update an environment variable's value by assigning to %ENV:

$ENV{VARNAME} = "value";

or:

my $varname = "VARNAME";
my $value = "value";
$ENV{$varname} = $value;

You can delete an environment variable in Perl with:

delete $ENV{VARNAME};

And in ksh this would correspond to "export varname=value"?

These examples are both equivalent to the (Korn, Bash, Bourne) shell notation:

export VARNAME="value"

or, if you're stretching the limits a bit, the second is equivalent to:

varname="VARNAME"
value="value"
export $varname="$value"