| 1 |
.\" -*- mode: troff; coding: utf-8 -*- |
| 2 |
.\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45) |
| 3 |
.\" |
| 4 |
.\" Standard preamble: |
| 5 |
.\" ======================================================================== |
| 6 |
.de Sp \" Vertical space (when we can't use .PP) |
| 7 |
.if t .sp .5v |
| 8 |
.if n .sp |
| 9 |
.. |
| 10 |
.de Vb \" Begin verbatim text |
| 11 |
.ft CW |
| 12 |
.nf |
| 13 |
.ne \\$1 |
| 14 |
.. |
| 15 |
.de Ve \" End verbatim text |
| 16 |
.ft R |
| 17 |
.fi |
| 18 |
.. |
| 19 |
.\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. |
| 20 |
.ie n \{\ |
| 21 |
. ds C` "" |
| 22 |
. ds C' "" |
| 23 |
'br\} |
| 24 |
.el\{\ |
| 25 |
. ds C` |
| 26 |
. ds C' |
| 27 |
'br\} |
| 28 |
.\" |
| 29 |
.\" Escape single quotes in literal strings from groff's Unicode transform. |
| 30 |
.ie \n(.g .ds Aq \(aq |
| 31 |
.el .ds Aq ' |
| 32 |
.\" |
| 33 |
.\" If the F register is >0, we'll generate index entries on stderr for |
| 34 |
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index |
| 35 |
.\" entries marked with X<> in POD. Of course, you'll have to process the |
| 36 |
.\" output yourself in some meaningful fashion. |
| 37 |
.\" |
| 38 |
.\" Avoid warning from groff about undefined register 'F'. |
| 39 |
.de IX |
| 40 |
.. |
| 41 |
.nr rF 0 |
| 42 |
.if \n(.g .if rF .nr rF 1 |
| 43 |
.if (\n(rF:(\n(.g==0)) \{\ |
| 44 |
. if \nF \{\ |
| 45 |
. de IX |
| 46 |
. tm Index:\\$1\t\\n%\t"\\$2" |
| 47 |
.. |
| 48 |
. if !\nF==2 \{\ |
| 49 |
. nr % 0 |
| 50 |
. nr F 2 |
| 51 |
. \} |
| 52 |
. \} |
| 53 |
.\} |
| 54 |
.rr rF |
| 55 |
.\" ======================================================================== |
| 56 |
.\" |
| 57 |
.IX Title "Env 3perl" |
| 58 |
.TH Env 3perl 2025-11-16 "perl v5.40.1" "Perl Programmers Reference Guide" |
| 59 |
.\" For nroff, turn off justification. Always turn off hyphenation; it makes |
| 60 |
.\" way too many mistakes in technical documents. |
| 61 |
.if n .ad l |
| 62 |
.nh |
| 63 |
.SH NAME |
| 64 |
Env \- perl module that imports environment variables as scalars or arrays |
| 65 |
.SH SYNOPSIS |
| 66 |
.IX Header "SYNOPSIS" |
| 67 |
.Vb 3 |
| 68 |
\& use Env; |
| 69 |
\& use Env qw(PATH HOME TERM); |
| 70 |
\& use Env qw($SHELL @LD_LIBRARY_PATH); |
| 71 |
.Ve |
| 72 |
.SH DESCRIPTION |
| 73 |
.IX Header "DESCRIPTION" |
| 74 |
Perl maintains environment variables in a special hash named \f(CW%ENV\fR. For |
| 75 |
when this access method is inconvenient, the Perl module \f(CW\*(C`Env\*(C'\fR allows |
| 76 |
environment variables to be treated as scalar or array variables. |
| 77 |
.PP |
| 78 |
The \f(CWEnv::import()\fR function ties environment variables with suitable |
| 79 |
names to global Perl variables with the same names. By default it |
| 80 |
ties all existing environment variables (\f(CW\*(C`keys %ENV\*(C'\fR) to scalars. If |
| 81 |
the \f(CW\*(C`import\*(C'\fR function receives arguments, it takes them to be a list of |
| 82 |
variables to tie; it's okay if they don't yet exist. The scalar type |
| 83 |
prefix '$' is inferred for any element of this list not prefixed by '$' |
| 84 |
or '@'. Arrays are implemented in terms of \f(CW\*(C`split\*(C'\fR and \f(CW\*(C`join\*(C'\fR, using |
| 85 |
\&\f(CW$Config::Config{path_sep}\fR as the delimiter. |
| 86 |
.PP |
| 87 |
After an environment variable is tied, merely use it like a normal variable. |
| 88 |
You may access its value |
| 89 |
.PP |
| 90 |
.Vb 2 |
| 91 |
\& @path = split(/:/, $PATH); |
| 92 |
\& print join("\en", @LD_LIBRARY_PATH), "\en"; |
| 93 |
.Ve |
| 94 |
.PP |
| 95 |
or modify it |
| 96 |
.PP |
| 97 |
.Vb 2 |
| 98 |
\& $PATH .= ":/any/path"; |
| 99 |
\& push @LD_LIBRARY_PATH, $dir; |
| 100 |
.Ve |
| 101 |
.PP |
| 102 |
however you'd like. Bear in mind, however, that each access to a tied array |
| 103 |
variable requires splitting the environment variable's string anew. |
| 104 |
.PP |
| 105 |
The code: |
| 106 |
.PP |
| 107 |
.Vb 2 |
| 108 |
\& use Env qw(@PATH); |
| 109 |
\& push @PATH, \*(Aq/any/path\*(Aq; |
| 110 |
.Ve |
| 111 |
.PP |
| 112 |
is almost equivalent to: |
| 113 |
.PP |
| 114 |
.Vb 2 |
| 115 |
\& use Env qw(PATH); |
| 116 |
\& $PATH .= ":/any/path"; |
| 117 |
.Ve |
| 118 |
.PP |
| 119 |
except that if \f(CW$ENV{PATH}\fR started out empty, the second approach leaves |
| 120 |
it with the (odd) value "\f(CW\*(C`:/any/path\*(C'\fR", but the first approach leaves it with |
| 121 |
"\f(CW\*(C`/any/path\*(C'\fR". |
| 122 |
.PP |
| 123 |
To remove a tied environment variable from |
| 124 |
the environment, assign it the undefined value |
| 125 |
.PP |
| 126 |
.Vb 2 |
| 127 |
\& undef $PATH; |
| 128 |
\& undef @LD_LIBRARY_PATH; |
| 129 |
.Ve |
| 130 |
.SH LIMITATIONS |
| 131 |
.IX Header "LIMITATIONS" |
| 132 |
On VMS systems, arrays tied to environment variables are read-only. Attempting |
| 133 |
to change anything will cause a warning. |
| 134 |
.SH AUTHOR |
| 135 |
.IX Header "AUTHOR" |
| 136 |
Chip Salzenberg <\[email protected]\fR> |
| 137 |
and |
| 138 |
Gregor N. Purdy <\[email protected]\fR> |