<p>I have a framework written in Perl that sets a bunch of environment variables to support  interprocess (typically it is sub process) communication.  We keep a sets of key/value pairs in XML-ish files.  We tried to make the key names camel-case <code>somethingLikeThis</code>.  This all works well.</p>

<p>Recently we have had occasion to pass control (chain) processes from Windows to UNIX.  When we spit out the <code>%ENV</code> hash to a file from Windows the <code>somethingLikeThis</code> key becomes <code>SOMETHINGLIKETHIS</code>.  When the Unix process picks up the file and reloads the environment and looks up the value of <code>$ENV{somethingLikeThis}</code> it does not exist since UNIX is case sensitive (from the Windows side the same code works fine).  </p>

<p>We have since gone back and changed all the keys to UPPERCASE and solved the problem, but that was tedious and caused pain to the users.  Is there a way to make Perl on Windows preserve the character case of the keys of the environment hash?</p>

[{'answer_id': 40964, 'author': 'dguaraglia', 'author_id': 2384, 'author_profile': 'https://Stackoverflow.com/users/2384', 'pm_score': 2, 'selected': False, 'text': '<p>As far as I remember, using ALL_CAPS for environment variables is the recommended practice in both Windows and *NIX worlds. My guess is Perl is just using some kind of legacy API to access the environment, and thus only retrieves the upper-case-only name for the variable.</p>\n\n<p>In any case, you should never rely on something like that, even more so if you are asking your users to set up the variables, just imagine how much aggravation and confusion a simple misspelt variable would produce! You have to remember that some OSes that will remain nameless have not still learned how to do case sensitive files...</p>\n'}, {'answer_id': 42680, 'author': 'Jack M.', 'author_id': 3421, 'author_profile': 'https://Stackoverflow.com/users/3421', 'pm_score': 2, 'selected': False, 'text': "<p>I believe that you'll find the Windows environment variables are actually case insensitive, thus the keys are uppercase in order to avoid confusion.\nThis way Windows scripts which don't have any concept of case sensitivity can use the same variables as everything else.</p>\n"}, {'answer_id': 47463, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>Jack M.: Agreed, it is not a problem on Windows.  If I create an environment variable Foo I can reference it in Perl as $ENV{FOO} or $ENV{fOO} or $ENV{foo}.  The problem is:  I create it as Foo and dump the entire %ENV to a file and then read in the file from *NX to recreate the Environment hash and use the same script to reference $ENV{Foo}, that hash value does not exist (the $ENV{FOO} does exist).  </p>\n\n<p>We had adopted the all UPPERCASE workaround that davidg suggested.  I was just wondering if there was ANY way to "preserve case" when writing out the keys to the %ENV hash from Perl on Windows.</p>\n'}, {'answer_id': 52166, 'author': 'Jack M.', 'author_id': 3421, 'author_profile': 'https://Stackoverflow.com/users/3421', 'pm_score': 0, 'selected': False, 'text': "<p>To the best of my knowledge, there is not.  It seems that you may be better off using another hash instead of %ENV.  If you are calling many outside modules and want to track the same variables across them, a Factory pattern may work so that you're not breaking DRY, and are able to use a case-sensitive hash across multiple modules.  The only trick would then be to keep these variables updated across all objects from the Factory, but I'm sure you can work that out.</p>\n"}, {'answer_id': 73849, 'author': 'piCookie', 'author_id': 8763, 'author_profile': 'https://Stackoverflow.com/users/8763', 'pm_score': 2, 'selected': False, 'text': '<p>First, to solve your problem, I believe using backticks around set and parsing it yourself will work. On my Windows system, this script worked just fine.</p>\n\n<pre><code>my %env = map {/(.*?)=(.*)/;} `set`;\nprint join(\' \', sort keys %env);\n</code></pre>\n\n<p>In the camel book, the advice in Chapter 25: Portable Perl, the System Interaction section is "Don\'t depend on a specific environment variable existing in %ENV, and don\'t assume that anything in %ENV will be case sensitive or case preserving. Don\'t assume Unix inheritance semantics for environment variables; on some systems, they may be visible to all other processes."</p>\n'}]
['https://Stackoverflow.com/questions/40923', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']