Pardus has asked for the wisdom of the Perl Monks concerning the following question:
Maybe I'm touching some deep voodoo here, but how does one replace the version of %ENV that is used for child processes ? It seems like %ENV is just an ordinary hash, only with 'magic' scope, but the copy for forked processes isn't exactly what I expected :((
To put my question directly: how is %ENV copied by child processes ?
Some evil test code:The behaviour I'm looking for is that the forked processes use my modified ENV.#!/usr/bin/perl package Env::Tie; use strict; use Tie::Hash; our @ISA = qw/Tie::StdHash/; sub TIEHASH { bless $_[1] , $_[0] } sub FETCH { $_[0]->{$_[1]} . '---BWUBUBWU' } # The '---BWUBUBWU' of course being # dynamic generated content package Test; use strict; sub print { print 'env home =', $ENV{HOME}, "\n" } package main; use strict; print "Hic sunt leones\n"; print 'env home =', $ENV{HOME}, "\n"; print "lets go\n"; my %self = %ENV; tie %ENV, 'Env::Tie', \%self; print "tied ENV\n"; print 'env home =', $ENV{HOME}, "\n"; print "lets try it in an other package\n"; Test::print(); print "lets fork perl\n"; system( 'perl', '-e', q{print 'env home =', $ENV{HOME}, "\n"} ); print "lets fork bash\n"; system( 'bash', '-c', q{echo $HOME} ); print "done\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
•Re: How is %ENV copied by child processes ?
by merlyn (Sage) on Apr 21, 2003 at 17:58 UTC | |
by Pardus (Pilgrim) on Apr 21, 2003 at 18:56 UTC | |
|
Re: How is %ENV copied by child processes ? (untie)
by tye (Sage) on Apr 21, 2003 at 20:36 UTC | |
by Pardus (Pilgrim) on Apr 22, 2003 at 10:52 UTC |