but %ENV is magical
%ENV appears to be magical only under shells where the lookup and expansion of environmental variables is a case-insensitve operation.

$ set comspec ComSpec=C:\WINDOWS\system32\cmd.exe $ echo %comspec% C:\WINDOWS\system32\cmd.exe $ echo %COMSPEC% C:\WINDOWS\system32\cmd.exe $ perl -le "print 'comspec : ', $ENV{comspec}" comspec : C:\WINDOWS\system32\cmd.exe $ perl -le "print 'COMSPEC : ', $ENV{COMSPEC}" COMSPEC : C:\WINDOWS\system32\cmd.exe
On systems (shells rather) where there is a distinction between the case-sensitivity of Env. Vars, %ENV behaves rather normally like a hash should.
$ set | grep -i ^shell shell /bin/tcsh $ echo $shell /bin/tcsh $ echo $SHELL $ perl -le 'print "shell : ", $ENV{shell}' shell : $ perl -le 'print "SHELL : ", $ENV{SHELL}' SHELL : /bin/bash
It's likely %ENV is tied (I am guessing) or has mechanism similar to tie associated with it to pass lookups to an underlying system call. It should be noted that not all environmental varaibles are populated into %ENV and in other cases, the values of %ENV contradict those of the shell (as shown above). Don't rely too heavily on information or its validity presented to you in %ENV;

There is a difference between %ENV and Win32::ExpandEnvironmentStrings.

%ENV holds literals (just like the shell, in most cases atleast), Win32::ExpandEnvironmentStrings() tests the expansion of a literal in the win32 environment and returns it after substituting values defined for the current user.
$ set var var=%OS% $ perl -MWin32 -e "print $ENV{var} .= ' evaled' , ' => ', Win32::Expa +ndEnvironmentStrings($ENV{var})" %OS% evaled => Windows_NT evaled
For the purposes of delayed expansion in the environment, Win32::ExpandEnvironmentStrings() then takes a literal string of the form !Foo! rather than %Foo%.
$ set var=Foo $ set var var=Foo $ set var=Bar & perl -MWin32 -e "print Win32::ExpandEnvironmentStrings +('%var%')" Foo $ set var var=Bar $ set var=Baz & perl -MWin32 -e "print Win32::ExpandEnvironmentStrings +('!var!')" Baz $ set var var=Baz

In reply to Re^3: Win32 GetEnvironmentVariables? by Firefly258
in thread Win32 GetEnvironmentVariables? 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.