[Israel.pm] setenv in perl

Oron Peled oron at actcom.co.il
Thu Sep 2 12:34:02 PDT 2004

On Thursday 02 September 2004 16:16, Shlomi Bakish wrote:
> I'm working on unix platform.
> I have a device that uses a proriety programing language (very limited). 
> I can run a perl script from within the code,
> but the only 2 ways to get back a result, is by reading a file, or 
> reading environment variables.
> I don't want to use files for transfering a single result.
> how can I use perl to do setenv ? 'system' seems to use sh, no setenv there.

Every process in Unix has an environment. The way to get/set environment
variables depends on the language:
  setenv FOO bar
  FOO=bar; export FOO
  # Or if we ignore the original Bourne shell,
  # we can short-cut
  export FOO=bar
  $ENV{FOO} = 'bar';

> Even if I could do setenv, will it still be defined in the parent process ?

Now you ask the right question...
Of course it will not be defined by the parent, process
environment (which includes environment variables as well as
other attributes: umask, current dir, current root dir, ownership,
etc.) is inherited:

 A change in any part of the environment would affect
 only the same process or child processes created later.

Note that this is very important as it allowes us to run the
same program multiple times on the same computer (at the same
time) and have different behaviour. Example:

 env TZ=Europe/Paris xclock &
 env TZ=US/Pacific xclock &


Oron Peled                             Voice/Fax: +972-4-8228492
oron at actcom.co.il                  http://www.actcom.co.il/~oron
ICQ UIN: 16527398

"Complaining that [Linux] doesn't work well with Windows is like ...
oh, say, evaluating an early automobile and complaining that there's no
place to hitch up a horse."

Daniel Dvorkin, July 28, 2003 

More information about the Perl mailing list