Title: Environment variables
Ronald,
 
I haven't personally used this but I found it in the Perl Bookshelf from O'Reilly.
 

7.2.14 Env- Import Environment Variables

use Env;                                         # import all possible variables
use Env qw(PATH HOME TERM);    # import only specified variables

Perl maintains environment variables in a pseudo-associative array named %ENV. Since this access method is sometimes inconvenient, the Env module allows environment variables to be treated as simple variables.

The Env::import() routine ties environment variables to global Perl variables with the same names. By default it ties suitable, existing environment variables (that is, variables yielded by keys %ENV). An environmental variable is considered suitable if its name begins with an alphabetic character, and if it consists of nothing but alphanumeric characters plus underscore.

If you supply arguments when invoking use Env, they are taken to be a list of environment variables to tie. It's OK if the variables don't yet exist.

After an environment variable is tied, you can use it like a normal variable. You may access its value:

@path = split(/:/, $PATH);

or modify it any way you like:

$PATH .= ":.";

To remove a tied environment variable from the environment, make it the undefined value:

undef $PATH;

Note that the corresponding operation performed directly against %ENV is not undef, but delete:

delete $ENV{PATH};

Matt Schneider
Programmer/System Administrator
SKLD Information Services, LLC

-----Original Message-----
From: Mundell, R. (Ronald) [mailto:[EMAIL PROTECTED]]
Sent: Thursday, December 19, 2002 11:54 PM
To: Perl-Win32-Users (E-mail); Perl-Unix-Users (E-mail)
Subject: [Perl-unix-users] Environment variables

Good Day All

How do one set an Environment variable out of a perl script, let say PATH?

Ronald

Reply via email to