The use of the ENV environment variable by Perl

Source: Internet
Author: User
Tags scalar

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.