Why is a tied %::ENV hash not passed to child processes?

Keary Suska hierophant at pcisys.net
Fri May 2 18:21:11 CDT 2003


on 5/2/03 4:53 PM, dave.waddell at mci.com purportedly said:

> Instead of having ksh wrappers to perl rsh and cron scripts to provide
> them with an environment, I have been experimenting with
> using tied hashes. A tied %::ENV hash won't work. I was wondering
> if anyone knows why. You can tie the DB files to a different hash
> and copy the values over to get it to work.

%ENV is a magical variable, which is probably the problem. I am not sure how
Perl internally handles exporting the contents of %ENV when a child process
is launched, but chances are, it happens entirely internally without
reference to any runtime constructs, such as tie().

You will likely have to use the second code snippet, but you could cut it
down to one line by creating a module that handless the environment import.
In this case, you don't even need a wrapper or initializer, as the child
process could load the environment itself.

> This doesn't work (child_process doesn't get the %ENV):
> 
> #!/usr/local/bin/perl
> use NDBM_File;
> tie(%::ENV,'NDBM_File','/home/gkancir/bin/Infra_1_3_ENV',0x2|0x100,0666);
> system "child_process";
> 
> This does work:
> 
> #!/usr/local/bin/perl
> use NDBM_File;
> tie(%MY_ENV,'NDBM_File','/home/gkancir/bin/Infra_1_3_ENV',0x2|0x100,0666);
> while(($key,$value) = each %MY_ENV){
> $ENV{$key} = $value;
> print $key,"=",$value,"\n";
> }
> untie %MY_ENV;
> system "child_process";
> 


Keary Suska
(719) 473-6431
(719) 440-9952 (cell)




More information about the Pikes-peak-pm mailing list