Scripting code for Perl operating system environment variables _perl

Source: Internet
Author: User
Tags hash perl script

How do I use the Perl script operating system environment variables?

Presumably a lot of friends will soon think of this particular hash variable that $env in Perl, and, yes, you can get some system variables in $env. How do I get it? For example, to know the contents of the system environment variable of Path, we can get it by $env{' Path '. If you want to set Path for this environment variable, ha, use $env{' Path '}= ' C:\Windows\System32 ' to set it. To get all the list of environment variables is also very simple, hash traversal can not be

In fact, the real question in this article is that you have set an environment variable through the above method, right click on the "My Computer" properties, select the middle-and-middle tab to see the value of the path variable really changed it? In fact, the careful you will find, completely unchanged! But do not complain that Perl deceives you, it does not deceive you, but you do not really understand. In fact, the path variable can be set by setting $env{' Path ', but the change caused by this setting is only the session level, which is your program level. If you do not understand, you can imagine that after opening a CMD, enter the effect of set path= "C:\\royen", that is, the PATH environment variable is "C:\\royen" in this window, And you open a new window after cmd the path variable will find it is completely not "C:\\royen";

So to really add or change a system environment variable, we need to turn to the registry to help. Just find the location where the environment variable is stored in the registry.
General system variables can be found under registry HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment.

Realize:

Copy Code code as follows:

My $loc = "System\\currentcontrolset\\control\\session manager\\environment";
My $regkey;
$HKEY _local_machine->open ($loc, $regkey) | | Die "Open Registry fail,information:$!\n";
$regkey->setvalueex ("Perllib", 0,REG_SZ, "c:\\staf\\bin;c:\\staf\\bin\\perl58");

After you add an environment variable, remember to restart the machine for it to take effect.

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.