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

David R. Waddell dave.waddell at mci.com
Mon May 5 10:16:41 CDT 2003


Hi Keary,
The child processes that I am starting are not normally in perl, so
they can't have a "use" statement. Using a module is a good idea anyway.
It would introduce one more layer of abstraction that would allow
the implementation of the environment to change without doing any
changes in all the scripts that load the environment. For example, if
something other than %::ENV needs to be done, I could do it in the
module without changing the scripts.
David
At 17:21 5/2/2003, you wrote:
>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