Fastolfe pretty much covered %ENV, but seemed a little unsure on the details, so I'll reiterate with a little more information. :-) (++ for Fastolfe though!)

When Perl starts up it creates the %ENV associated array, which contains all your environment variables of the calling process (usually the shell). To catch a quick glimpse of the contents, do something like this:

perl -MData::Dumper -we "print Data::Dumper->Dump([\%ENV], ['ENV']);"
Which should make things pretty clear. You can edit any of these elements as you would any hash. Whenever you create a child process (or a system call or what-have-you) Perl passes this %ENV hash to that process to use. Thus everything below you becomes effected by your changes. However, this hash is not passed UP to the calling process, only down to the children.

To make permenant changes on an MSWin32 system you need to muck with the registry. A great way to do that is Win32::TieRegistry. Do so, however, at your own risk.

Update:I just remembered that this is a FAQ!, check out "How can I change the environment from within my Perl script?." I remembered because my post seemed familliar, and then I remembered answering this in Q&A.


In reply to RE: How to access system environment variables? by Adam
in thread How to access system environment variables? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.