http://www.perlmonks.org?node_id=1083810

kartlee05 has asked for the wisdom of the Perl Monks concerning the following question:

Hi Folks, I try to set an ENV in BEGIN block and load a module. The dll loaded by the module does't see the env. If I run system("set"), just after the env is set, I do see the env in the list. Is there a bug in perl win32 in handling environment through cached block that affect the module from seeing it?
#!/usr/bin/env perl BEGIN { $ENV{TEST} = "CHECK"; require module; # use module; doesn't work too. } print module::check_env(), "\n";
-Karthik

Replies are listed 'Best First'.
Re: Win32 Perl fail to see the set ENV in loaded module
by Lotus1 (Vicar) on Apr 25, 2014 at 17:21 UTC
      I see the reported issue only for Windows. BTW, I updated the ticket with the code. Please check.
Re: Win32 Perl fail to see the set ENV in loaded module
by mr_mischief (Monsignor) on Apr 25, 2014 at 17:28 UTC

    By "load a module" do you mean using use module; or require module;? The use happens at compile time. A require on the other hand works at runtime.

    Seeing the actual code may be helpful.

      I just updated the ticket with the code. 'use' or 'require' seem to be behaving same in this case.

        I don't have Windows handy to test at the moment. It is my suspicion that the DLL is grabbing the environment from somewhere other than the current process. The module itself should be reflecting the current process's environment since it is part of the current process.The BEGIN block shouldn't even be necessary.

        Since you're working with a specific DLL, you may want to check the programmer's documentation for that DLL.