1.hash mode access. %env key is the environment variable name, value is the environment variable
2. Call the ENV module. Use Env QW (PATH);
Print "path is $ENV {path}\n";
This code creates (or overwrites) the Perlvar variable in the environment.
$ENV {Perlvar} = "Perl Tech Tips";
To delete an environment variable, use delete. The following example removes the temporary environment variable:
Delete $ENV {temp};
The second way to access environment variables is to use the Env module. The Env module creates Perl scalar or array variables for each environment variable.
You can specify the specific variables to be imported, and you can import all the environment variables. If you specify an environment variable name, then they do not need to exist as environment variables.
If you want to access only the path variable, use the following code:
USEENVQW (PATH);
Print "The path is $PATH \ n";
If you do not specify the type of the variable, it is treated as a scalar. If you specify a variable as an array (for example, using ENVQW (@PATH)), then it is automatically segmented and merged by CONFIG::CONFIG{PATH_SEP} as a delimiter.
The following code creates (or overwrites, if it already exists) the Perlvar variable in the environment.
USEENVQW (Perlvar);
$PerlVar = "Perl Tech Tips";
Perl provides two different ways to access environment variables:%env hash and env module. Depending on your needs and your personal preferences for writing code, you can use either of these methods to access or change environment variables.
The use of the ENV environment variable by Perl