1N/AEnv - perl module that imports environment variables as scalars or arrays 1N/A use Env qw(PATH HOME TERM); 1N/A use Env qw($SHELL @LD_LIBRARY_PATH); 1N/APerl maintains environment variables in a special hash named C<%ENV>. For 1N/Awhen this access method is inconvenient, the Perl module C<Env> allows 1N/Aenvironment variables to be treated as scalar or array variables. 1N/AThe C<Env::import()> function ties environment variables with suitable 1N/Anames to global Perl variables with the same names. By default it 1N/Aties all existing environment variables (C<keys %ENV>) to scalars. If 1N/Athe C<import> function receives arguments, it takes them to be a list of 1N/Avariables to tie; it's okay if they don't yet exist. The scalar type 1N/Aprefix '$' is inferred for any element of this list not prefixed by '$' 1N/Aor '@'. Arrays are implemented in terms of C<split> and C<join>, using 1N/AC<$Config::Config{path_sep}> as the delimiter. 1N/AAfter an environment variable is tied, merely use it like a normal variable. 1N/AYou may access its value 1N/A @path = split(/:/, $PATH); 1N/A print join("\n", @LD_LIBRARY_PATH), "\n"; 1N/A push @LD_LIBRARY_PATH, $dir; 1N/Ahowever you'd like. Bear in mind, however, that each access to a tied array 1N/Avariable requires splitting the environment variable's string anew. 1N/Aexcept that if C<$ENV{PATH}> started out empty, the second approach leaves 1N/Ait with the (odd) value "C<:.>", but the first approach leaves it with "C<.>". 1N/ATo remove a tied environment variable from 1N/Athe environment, assign it the undefined value 1N/A undef @LD_LIBRARY_PATH; 1N/AOn VMS systems, arrays tied to environment variables are read-only. Attempting 1N/Ato change anything will cause a warning. 1N/AChip Salzenberg E<lt>F<chip@fin.uucp>E<gt> 1N/AGregor N. Purdy E<lt>F<gregor@focusresearch.com>E<gt> 1N/A eval "package $callpack; use vars qw(" .
join(
' ', @
vars) .
")";
1N/A###################################################################### 1N/A###################################################################### 1N/A while ($i <
127 and defined $
ENV{$$
self .
';' . $i}) { $i++; };