5 Env - perl module that imports environment variables
10 use Env qw(PATH HOME TERM);
14 Perl maintains environment variables in a pseudo-hash named %ENV. For
15 when this access method is inconvenient, the Perl module C<Env> allows
16 environment variables to be treated as simple variables.
18 The Env::import() function ties environment variables with suitable
19 names to global Perl variables with the same names. By default it
20 does so with all existing environment variables (C<keys %ENV>). If
21 the import function receives arguments, it takes them to be a list of
22 environment variables to tie; it's okay if they don't yet exist.
24 After an environment variable is tied, merely use it like a normal variable.
25 You may access its value
27 @path = split(/:/, $PATH);
34 To remove a tied environment variable from
35 the environment, assign it the undefined value
41 Chip Salzenberg E<lt>F<chip@fin.uucp>E<gt>
46 my ($callpack) = caller(0);
48 my @vars = grep /^[A-Za-z_]\w*$/, (@_ ? @_ : keys(%ENV));
51 eval "package $callpack; use vars qw("
52 . join(' ', map { '$'.$_ } @vars) . ")";
55 tie ${"${callpack}::$_"}, Env, $_;
69 my ($self, $value) = @_;
70 if (defined($value)) {
71 $ENV{$$self} = $value;